开发者

Silverlight Byte[] to its original file format

开发者 https://www.devze.com 2022-12-22 09:32 出处:网络
is there a way to convert byte[] to its original file format? Byte[] tempByte = new Byte[content.Length];

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

Byte[] tempByte = new Byte[content.Length];
tempByte = Convert.FromBase64String(c开发者_高级运维ontent);


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);


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消