How to trap errors on file uploads?

S

SalP

I'm using VS 2003.

I'm uplading a file using Input Type='File' .PostedFile. etc.
How does one trap the error when the file is larger than the 4 Meg
default? Try/Catch doesn't work. I get the "This page cannot be
displayed screen". I also tried adding a Page Error handler which
didn't work. I want to tell the user that the file size is too large.

Thanks,
Sal
 
N

Nathan Sokalski

I would look at the PostedFile.ContentLength property using an If statement.
For Example, see if something like the following works (I haven't tested it,
but I would expect it to work):


If myfile.PostedFile.ContentLength<=4194304 Then

End If


I think the reason for your problem has something to do with the order that
the operations are performed in, but since I am not an expert on that and I
haven't seen your code, I can't say for sure. Good Luck!
 
S

SalP

It doesn't get to the C# code-behind file. It displays "This page
cannot be displayed" and ignores the Try/Catch block.

Sal
 
B

bruce barker \(sqlwork.com\)

the http protocol does not support stopping an upload and returnning an
error to the browser. when asp.net detects the upload is too larger (by
counting how many bytes its received), it kills the connection to the
browser to stops the upload.

so while you can catch the error on the server and log it, you can not send
any message back to the browser, because the request failed (from the
browsers point of view) and the browser prints the error message of its
choice.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top