12

我有一个 asp.net FileUpload 控件。我可以成功上传文件以存储在会话中,但是当我试图获取其输入流时(我将文件存储在 HttpPosterFile 中)我收到错误

无法访问已关闭的文件

tr.PostedFile //<== HttpPostedFile; 
byte[] byteArray = null; 
using (var binaryReader = new BinaryReader(tr.PostedFile.InputStream)) 
{ 
    byteArray = binaryReader.ReadBytes(tr.PostedFile.ContentLength); 
}
4

2 回答 2

28

将此添加到您的 web.config 文件中

<system.web>
  <httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="15360" requestLengthDiskThreshold="15360"/>
</system.web>

http://sanjaysainitech.blogspot.com/2008/12/file-upload-error-can-not-access-closed.html

于 2013-12-09T10:17:59.727 回答
2

你用了using吗?

如果是,请注意在将字符串放入输入流之前不要关闭它。

于 2013-12-09T10:18:36.723 回答