Below is the code to convert an image into base64 string in C#.
Syntax
- static void Main(string[] args)
- {
- string imagePath=@"E:\images\sample.png";
- string imgBase64String = GetBase64StringForImage(imagePath);
- Console.WriteLine(imgBase64String);
- }
- protected static string GetBase64StringForImage(string imgPath)
- {
- byte[] imageBytes = System.IO.File.ReadAllBytes(imgPath);
- string base64String = Convert.ToBase64String(imageBytes);
- return base64String;
- }
Example



vikas singhPosted Apr 23, 2019, 4:53 AM EDT
Https://www.c-sharpcorner.com/blogs/get-base64-string-from-image-in-c-sharp
vikas singhPosted Apr 23, 2019, 4:52 AM EDT
Https://www.c-sharpcorner.com/blogs/get-base64-string-from-image-in-c-sharp
Masood KhaPosted Nov 9, 2017, 3:48 AM EST
Where is output is dumped bro. as i need in txt form
SubashPosted Aug 29, 2016, 1:28 AM EDT
Nice