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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File upload error

Status
Not open for further replies.

Jesse31

Programmer
Apr 5, 2002
7
CA
Does anyone know how to trap the error produced when trying to upload a file that's larger than that set to the maxRequestLength in the machine.config file. I don't want to make this value any larger than it is (roughly 4MB). I'd rather just catch the error and display a user friendly error instead. Thanks!
 
This is probably a dumb question on my part, but have you tried using a Try/Catch block?

Try
upload file
catch ex as exception
if ex.message = "file to big" then
msgbox("The file was too large to move")
else
msgbox(ex.message)
end if
end try

I am sure you have, but always like to start with the basic questions :)
 
That doesn't work as the file has already been posted in the request object and has broken the code by then.

Any other ideas??
 
Although, I am sure there is a way that you could trap the error between the page using the Catch block. The easiest way may be to increase (or remove) the file size in the machine.config file and then check the size of the file after the request page loads. As it will be hard to trap the error between the entry page and the requesting page. The one disadvantage of doing it this way is that you will temporarily load the file into memory until you are able to check the file size. Here is basicaly the code I would use:

MyFileCollection = Request.Files()
PostFile = MyFileCollection.Item("filename")
If PostFile.ContentLength > 4096 Then
postfile = nothing
'message to user
endif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top