[Solved] Convert Byte Array (byte) to HttpPostedFile in C# and VB.Net

Last Reply on Dec 28, 2017 12:06 AM By Mudassar

Posted on Dec 28, 2017 12:00 AM

Hi,

Kindly help me out. I want to convert byte array back to HttpPostedFile, please tell how?

I want to save the file using HttpPostedFile SaveAs method.

Thanks

 

Posted on Dec 28, 2017 12:06 AM

To save Byte Array back to File, you don't need HttpPostedFile, you can easily do using File class.

C#

//Save the Byte Array as File.
string filePath = "~/Files/" + fileName;
System.IO.File.WriteAllBytes(Server.MapPath(filePath), bytes);

VB.Net

'Save the Byte Array as File.
Dim filePath As String = "~/Files/" + fileName
System.IO.File.WriteAllBytes(Server.MapPath(filePath), bytes)