views:

205

answers:

2

Hi,

is there a way to convert byte[] to its original file format?

Byte[] tempByte = new Byte[content.Length];
tempByte = Convert.FromBase64String(content);
+1  A: 

If you have a Base64 encoded string, then yes Convert.FromBase64String will give you back a byte array identical to the one that was converted to a Base64 string.

However, your first line is unnecessary. You are allocating an array equal to the length of content which just gets overwritten by the return value from Convert.FromBase64String.

byte[] tempByte = Convert.FromBase64String(content);

File.WriteAllBytes(path, tempByte);
Josh Einstein
A: 

The byte array should already be having what you originally read from the file. Write the byte array to a file on the disk and you should be good to go!

NimsDotNet
Can you please illustrate on how to?
xscape
Josh's answer contains the required code.
NimsDotNet