cannot access a closed file – FileUpload in ASP.NET

Author posted by Jitendra on Posted on under category Categories ASP.NET and tagged as Tags , with 16 Comments on cannot access a closed file – FileUpload in ASP.NET

This was very interesting error, i got during development of file upload control in ASP.NET.

On my local system, every thing was just fine. but when i deployed my application on development server, my control was able to upload only small size files.

whenever i tried to upload large size file i got error “cannot access a closed file”

After going through MSDN i found that there is one new element added in ASP.NET 2.0 known as httpRuntime.

So i just added this new Tag in my web.config and every thing was right.

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

Note :

requestLengthDiskThreshold should not exceed the maxRequestLengthattribute.

To read more about this, please visit http://msdn.microsoft.com/en-us/library/e1f13641(VS.80).aspx

Related posts

16 thoughts on “cannot access a closed file – FileUpload in ASP.NET”

  1. Thank you. I finally solved the problem… The strange thing was that the error occourred also with small files (a 200KB PNG image). I only had a value (104857) for the first attribute (maxRequestLength) in my web.config, but not for the second. I added it with the same value and… everything’s working now.

  2. Just having the tag is not enough. You must provide a value for requestLengthDiskThreshold (up to maxRequestSize). Default is 80 KB, but if you don’t explicitly set the value, the framework closes the stream after it buffers the first chunk.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.