Upload PDF within a Button Click event - Cannot access a closed file

Answered
0
0

Hello guys!

I’ve been following the sample project who someone uploaded on this thread https://wisej.com/support/question/upload-file-by-coding. I want to upload a file when I click on the button. I put two global variables, one for the stream and another for the file name. Those variables are loaded when I upload the file, then those are sent and read to the save method when I click on the Save button. I got the message:

“Cannot access a closed file”

Can someone advise what I’m doing wrong? See attachment. Thanks in advance.

Attachment
  • You must to post comments
Best Answer
0
0

Hi Carlos,

You were missing the “requestLengthDiskThreshold” attribute in the “httpRuntime” Tag in your web.config file.

“requestLengthDiskThreshold” Specifies the limit for the input stream buffering threshold, in bytes. and its default value is 256.

So essentially, when you get the “Cannot access a closed file” exception, it’s just that the file in question was exceeding the limit.

I have modified the sample you provided, and I suggest that you take a look here: httpRuntime Element (ASP.NET Settings Schema) | Microsoft Docs for more info.

Please note: TherequestLengthDiskThreshold” should not exceed the “maxRequestLength” value.

HTH,
Alaa

Attachment
  • Carlos Lino
    Thank you so much! It worked.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.