file upload problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Thanks Richard and Shan,
I am using the HtmlInputFile control.But Shan where
exactly do you want me to put in your code? becoz,after
the user selects a file to upload and hits Submit, then
the flow of the code does not go into the OnClick() event
of the submit button, if the filesize is > 50 Mb.I checked
this by setting a breakpoint on the first line of the
OnClick event. The aspx page just shows a DNS error page.
Is there a way, that i can check the size of the file
before the user clicks submit maybe.
 
Try to catch the exception in the Application_Error event handler in
the global.asax file

Code:
=====

Dim AppEx As Exception = Server.GetLastError()
If AppEx.Message.CompareTo("Maximum request length exceeded.") = 0 Then
'this is an overlimit upload
'clear the error out
Server.ClearError()
'redirect to my error page
Response.Redirect("errorpage.aspx")
End If

Please let me know if this works for you.

Thank you,
John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
Thanks John. The code does go into the application error
event during debugging, but does not redirect the page to
the error page. i tried ALL three methods i.e.
response.redirect, server.transfer and server.execute. But
the error page is not displyed. My error page has just one
label on it which says " Error occured in file transfer" .
It still shows the DNS error page.
Please shed some light on this if u can. Thank you.
 
I'm having a problem similar to the one described by the first Richard who posted here: I'd like to avoid the "DNS Error" page by somehow catching the "Maximum request length exceeded." exception

The technique you proposed does catch the exception in global.asax, but the subsequent redirection fails. The "if" is executed, and the debugger shows the if block's statements being executed, but the redirection -- no matter how it's done -- never happens. The if-block finishes, and the "DNS Error" page appears. I've successfully trapped other errors in global.asax, and those redirections work fine

I have no need to upload terribly large files (no more than 2-3 MB), so I'd like to leave the 4 MB limit in place, but I can't seem to trap this error. The problem is primarily a usability issue: saving fat-fingered users the inconvenience of waiting for a big file to upload, only to learn it was the wrong file (which would happen if the max upload size were increased in Web.config). A client-side solution would be fine, too, except that there doesn't seem to be a "safe" way to determine a file's size before submitting the form

Has anyone found a solution to this problem? Can anyone categorically state that it has none

--Rich Armstron

----- John Soulis [MSFT] wrote: ----

Try to catch the exception in the Application_Error event handler in
the global.asax fil

Code
====

Dim AppEx As Exception = Server.GetLastError(
If AppEx.Message.CompareTo("Maximum request length exceeded.") = 0 The
'this is an overlimit uploa
'clear the error ou
Server.ClearError(
'redirect to my error pag
Response.Redirect("errorpage.aspx"
End I

Please let me know if this works for you

Thank you,
John Souli
 
Back
Top