I have inherited some C# code. This code needs to upload a picture to a web service. This code saves the bytes of picture into byte[]
called ImageBytes
. To ensure the greatest portability, I want to first encode the ImageBytes
into a base 64 encoded string. I believe the following code is doing that, however, I'm not sure. Can someone please verify if my assumption is correct?
StringBuilder sb = new StringBuilder();
this.ImageBytes.ToList<byte>().ForEach(x => sb.AppendFormat("{0}.", Convert.ToUInt32(x)));
Is this code converting my byte[]
into a base 64 encoded string?
Thank you!
Use the
Convert.ToBase64String()
method. It takes a byte array as parameter and returns the converted string.use methods
System.Convert.ToBase64String()
andSystem.Convert.FromBase64String()
for exampleNo, that's just converting it to a list of integers.
Use Convert.ToBase64String(). Assuming
ImageBytes
is abyte[]
: