Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Cannot access a closed file" when uploading a file

Status
Not open for further replies.

bboffin

Programmer
Nov 26, 2002
553
GB
I recently came across a problem when uploading files from an INPUT tag type=file. When I tried to process the uploaded file either using the SaveAs method or by accessing the stream I got an error "Cannot access a closed file" at random. It would always occur for some files but the same file could be uploaded successfully on a different server.

I eventually cleared the problem after much searching on the web by setting two new attributes in the httpRunTime tag in web.config.

These were:

maxRequestLength which should be set to about 50% larger than the largest file you wish to upload. I used 16000 (16MB as the value is in KB). It needs to be quite a bit larger than the maximum file size because it must allow for the rest of the Request including ViewState and for any conversion to Base64 of binary files.

requestLengthDiskThreshold which I set to 8192 (bytes). This was the one that fixed the problem for me. Other values will probably work but the default is stated to be 256 bytes.



Bob Boffin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top