How to save byte[] in c# application settings

Imran Shafqat picture Imran Shafqat · Sep 8, 2012 · Viewed 8.8k times · Source

I am trying to save a byte array (byte[]) in c# application settings that is returned by Object List View.

Can anyone give me a solution on how to save byte array in c# application settings? or some trick on how to convert byte[] to something like a string then store, then retrieve and again convert it to byte array and give it back to object list view.

Answer

Sergey Kalinichenko picture Sergey Kalinichenko · Sep 8, 2012

One of the most common ways to make a string from an array of bytes is encoding them in Base-64:

string encoded = System.Convert.ToBase64String(toEncodeAsBytes);

Use

byte[] bytes = System.Convert.FromBase64String(encoded);

to get your bytes back.