Search code examples
c#visual-studio-2010listviewapplication-settings

How to save byte[] in c# application settings


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.


Solution

  • 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.