Skip to main content

Get Base64 String From Image In C#

Below is the code to convert an image into the base64 string in C#.


static void Main(string[] args)  
     string imagePath=@"E:\images\sample.png";  
     string imgBase64String = GetBase64StringForImage(imagePath);  
protected static string GetBase64StringForImage(string imgPath)  
      byte[] imageBytes = System.IO.File.ReadAllBytes(imgPath);  
      string base64String = Convert.ToBase64String(imageBytes);  
      return base64String;  



One thought to “Get Base64 String From Image In C#”

  1. That is cool, it works, could you be knowing how to transfer the image to the ftp server from base64string?. i have tried it uploads even the actual size but when i download it, it does not show or open. so far i have tried,

Leave a Reply