在使用如下方式上传附件后(二进制保存在数据库中),图片类文件无法正常打开
Byte[] FileByteArray = new Byte[file.ContentLength];
using (Stream stream = file.InputStream)
{
stream.Read(FileByteArray, 0, file.ContentLength);
stream.Flush();
stream.Close();
stream.Dispose();
}
attContent.FileContent = FileByteArray;
原因:上传图片类文件时,Stream stream = file.InputStream 之后,stream.Position的位置是在最后,其它类型的位置是在0
解决方法:
Byte[] FileByteArray = new Byte[file.ContentLength];
using (Stream stream = file.InputStream)
{
stream.Position = 0;
stream.Read(FileByteArray, 0, file.ContentLength);
stream.Flush();
stream.Close();
stream.Dispose();
}
attContent.FileContent = FileByteArray;