C# Base64 String to PNG Image

Here’s how you can save a base64 encoded string to image file in C#.

public void SaveImageFile(string filename, string base64Image)
    string destinationImgPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + Constants.UserImagesPath+"\\"+filename+".png";
        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + Constants.UserImagesPath);
    catch (IOException iox)
        Console.WriteLine(iox.Message+" "+iox.Data);
    var bytes = Convert.FromBase64String(base64Image);
    using (var imageFile = new FileStream(destinationImgPath, FileMode.Create))
        imageFile.Write(bytes, 0, bytes.Length);

Vivek Maskara

I am pursuing BTech in Software Engineering from Delhi Technological University. I develop apps, create websites and blog about my app experiences.

Read more:
How to create your first Windows Phone app
How to change the App name and Tile name of your Windows phone app
Data binding in Windows Phone app – One way binding