Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "Cannot access a closed file" errormessage when getting file from session

I have a asp.net FileUpload control. I can successfully upload file to store in session, but when I am tring to get its inputstream (I'm store file in HttpPosterFile) I'm getting error

Cannot access a closed file

tr.PostedFile //<== HttpPostedFile; 
byte[] byteArray = null; 
using (var binaryReader = new BinaryReader(tr.PostedFile.InputStream)) 
{ 
    byteArray = binaryReader.ReadBytes(tr.PostedFile.ContentLength); 
}
like image 897
Jaztingo Avatar asked Dec 09 '13 10:12

Jaztingo


2 Answers

add this to your web.config file

<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

like image 138
Indranil.Bharambe Avatar answered Oct 08 '22 22:10

Indranil.Bharambe


Did you use using?

If yes pay attention to not close this before you put the string to the inputstream.

like image 41
Hadash Avatar answered Oct 08 '22 20:10

Hadash