且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从 HttpPostedFile 创建字节数组

更新时间:2023-11-15 18:54:22

使用 BinaryReader 对象从流中返回一个字节数组,如:

Use a BinaryReader object to return a byte array from the stream like:

byte[] fileData = null;
using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
{
    fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength);
}