HttpPostedFile.ContentLength Property

  • Thread starter Thread starter Stephen Travis
  • Start date Start date
S

Stephen Travis

Does anyone know if the HttpPostedFile.ContentLength Property is determined
BEFORE or AFTER the file actually reaches the server. I'd like to limit the
size of an file upload but uploading a Gb file only to tell the user that
they're limited to 1Mb seems like not so good an idea.

If the HttpPostedFile.ContentLength Property can't tell you BEFORE the
upload, is there another way to do this?

I'm aware of the maxRequestLength parameter in the machine.config but there
appears to be no way to capture this event in code.
 
This is definately caught on the server side but you would have to write some
code to prevent your users from uploading large files. So you must write
all of your code in a IF Block

If HttpPostedFile.ContentLength > 1024 (1 meg or whatever you want) Then
'upload your code
Else
'tell the user this is a no no!
End if

So, in this case you dont stream the contents of your file to the server.
 
Back
Top