Convert HttpPostedFile To Byte Array in .NET
To Convert HttpPostedFile
To Byte Array in .NET, you should follow the below steps in details:
1 - Write a method with name ConvertHttpPostedFileToByteArray that covert file to Byte[]
public byte[] ConvertHttpPostedFileToByteArray(HttpPostedFileBase file)
{
try
{
if (file != null && file.ContentLength > 0)
{
using (BinaryReader reader = new BinaryReader(file.InputStream))
{
return reader.ReadBytes(file.ContentLength);
}
}
}
catch (Exception ex)
{
LogMiddleware.LogError(ex, "ConvertHttpPostedFileToByteArray");
return null;
}
return null;
}