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.

<httpRuntime  maxRequestLength="15360" requestLengthDiskThreshold="15360"/>

Note :

requestLengthDiskThreshold should not exceed the maxRequestLengthattribute.

To read more about this, please visit


  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 comment

Your email address will not be published.

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