469,602 Members | 1,747 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

How to trap errors on file uploads?

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

May 17 '06 #1
3 1051
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!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"SalP" <sa*************@yahoo.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
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

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

Sal

Nathan Sokalski wrote:
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!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"SalP" <sa*************@yahoo.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
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


May 17 '06 #3

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)
"SalP" <sa*************@yahoo.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
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

May 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.