title: C# - Converting multi page tiff file to base64 string and converting back results with single image
body: <p>I'm opening a tiff file from local disk:</p>
  
  <pre><code>Image multiPageImage = Image.FromFile(fileName);
  </code></pre>
  
  <p>Then sending it to conversion method:</p>
  
  <pre><code>base64string = ImageToBase64(multiPageImage, ImageFormat.Tiff);
  
  public static string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format)
          {
              using (MemoryStream ms = new MemoryStream())
              {
                  // Convert Image to byte[]
                  image.Save(ms, format);
                  byte[] imageBytes = ms.ToArray();
  
                  // Convert byte[] to Base64 String
                  string base64String = Convert.ToBase64String(imageBytes);
                  return base64String;
              }  
          }
  </code></pre>
  
  <p>Finally I convert my base64 to tiff file with the below code:</p>
  
  <pre><code>public static void ConvertBase64ToTiff(string base64string)
      {
          Byte[] bitmapData = new Byte[base64string.Length];
  
          bitmapData = Convert.FromBase64String(FixBase64ForImage(base64string));
  
          using (MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData))
          {
              Bitmap bitImage = new Bitmap((Bitmap)Image.FromStream(streamBitmap));
              bitImage.Save(@"C:\myTiff.tiff");
          }            
      }
  
      public static string FixBase64ForImage(string base64string)
      {
          System.Text.StringBuilder sbText = new System.Text.StringBuilder(base64string, base64string.Length);
  
          sbText.Replace("\r\n", String.Empty);
          sbText.Replace(" ", String.Empty);
  
          return sbText.ToString();
      }
  </code></pre>
  
  <p>That fixing method is not mine. Actually I don't know if it is the right way or not. But I searched everwhere and trying what I find.</p>
  
  <p>My tests showed that base64 string has just a single image. </p>
  
  <p>Any help would be greatly appreciated!</p>