I created a web service that returns a (binary) file. Unfortunately, I cannot use byte [], so I need to convert an array of bytes to a string. What I'm doing at the moment is the following (but this does not work):
Convert file to string:
byte[] arr = File.ReadAllBytes(fileName);
System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding();
string fileAsString = enc.GetString(arr);
To check if this works correctly, I convert it via:
System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding();
byte[] file = enc.GetBytes(fileAsString);
But at the end, the original byte array and the byte array created from the string are not equal. Should I use a different method to read the file into an array of bytes?
source
share