How can I read and convert to text file this byte[] value?

It is described in documentation like DataType="base64Binary" but I cant convert it to human readable format...
I have tried:
System.Text.Encoding.ASCII.GetString(gadsContent.Value)
and got
?\b\0\0\0\0\0\0\0?ZY??Zr~?W5vp??\0?t??6@\b\t???pL\bm\b???8?????/^~????L?/Q@Q??????...
Convert.ToBase64String(gadsContent.Value)
and got
H4sIAAAAAAAAANVaWZPiWnJ+51cQNRETdnCrtAAC9XT1jDZACAm0guRwTAhtCLSAFrQ4/OCxw3/AL15+hp8c9ttM/y8fUUBR273d99qecEd3FTonM09uJzM/0Z9/W4...
Update:
Now I read that this has compression GZIP... How can I decompress and decode it ?
You can use System.Text.Encoding class to convert between string and byte array. Based on the encoding of your input string/byte array, use the appropriate property from this class.
Here is a sample for UTF8 encoding.
var someString = "Some text input";
//Convert the string to byte array
var byteArray= System.Text.Encoding.UTF8.GetBytes(someString);
//Convert a byte array to string
var stringFromByteArray = System.Text.Encoding.UTF8.GetString(byteArray);
You have many other encoding options in this class. Use the one as needed
If a file contains a base64-encoded binary array, you need to follow these steps:
Open the file as text, using appropriate text encoding (ASCII, UTF8, etc). You can ask .NET to try to detect the encoding if you want.
Read the text into a string.
Convert the string into a byte array using Convert.FromBase64String().
The shortest possible example I could come up with looks like this:
string text = System.IO.File.ReadAllText(filePath, Encoding.UTF8);
byte[] byteArray = Convert.FromBase64String(text);
If you don't know the encoding, you can omit the argument and hope .NET can detect it:
string text = System.IO.File.ReadAllText(filePath);
byte[] byteArray = Convert.FromBase64String(text);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With