在这里,我试图将文件上传到数据库中,但是我在数据库中得到NULL
请给我任何提示。
var httpRequest = HttpContext.Current.Request;
var httpPostedFile = HttpContext.Current.Request.Files["file"];
foreach(string file in httpRequest.Files)
{
var postedfile = httpRequest.Files[file];
var FileName = httpPostedFile.FileName;
int fileSize = httpPostedFile.ContentLength;
byte[] fileByteArray = new byte[fileSize];
httpPostedFile.InputStream.Read(fileByteArray, 0, fileSize);
HttpPostedFile postedFile = HttpContext.Current.Request.Files[file];
byte[] bytes;
using(BinaryReader br = new BinaryReader(postedFile.InputStream))
{
bytes = br.ReadBytes(postedFile.ContentLength);
}
Temp_Table = new Temp_Table {
Profiledata = bytes
};
db.Table.Add(_temp);
db.SaveChanges();