Unable to access private file

I have an ASP.NET FileUpload control that works fine until I deploy it. Then it works fine if the file does not exceed ~ 55kb. I think this has something to do with postbacks and that I should put it in a session variable. However, it works for small files.

Perhaps this is a limitation on how large the session variable is? But it works when working with my IDE, so I'm not sure.

System.ObjectDisposedException: Unable to access closed file

Thanks for any conclusions.

+6
source share
2 answers

This can be resolved by providing DiskBufferSize in the web.config file:

<system.web> <httpRuntime executionTimeout="90" maxRequestLength="20000" useFullyQualifiedRedirectUrl="false" requestLengthDiskThreshold="8192"/> </system.web> 

per Unable to access private file

+7
source

I checked this, and it seems that installing DiskBufferSize bypasses the issue by disabling buffering. Now the computer will use more memory. Now buffering is effectively disabled. and the productivity you get from her is gone.

I think the correct solution is to use the SaveAs method to save the published file to a temporary folder in the FIRST postback and save the path to the temp file in the viewstate or session.

After any additional message or redirection, especially if asynchronous threads are involved, the SaveAs function will not work if buffering is required; You will receive the error "Unable to access the closed file."

I do not know what you have enclosed in your "session variable", but I assume that it is a file control, which is the problem.

This resolved the issue for me if others are working on it but don't want to disable buffering.

+2
source

All Articles