How to trap errors on file uploads?

Discussion in 'ASP .Net' started by SalP, May 17, 2006.

  1. SalP

    SalP Guest

    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
    SalP, May 17, 2006
    #1
    1. Advertising

  2. 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

    http://www.nathansokalski.com/

    "SalP" <> wrote in message
    news:...
    > 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
    >
    Nathan Sokalski, May 17, 2006
    #2
    1. Advertising

  3. SalP

    SalP Guest

    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
    >
    > http://www.nathansokalski.com/
    >
    > "SalP" <> wrote in message
    > news:...
    > > 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
    > >
    SalP, May 17, 2006
    #3
  4. 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" <> wrote in message
    news:...
    > 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
    >
    bruce barker \(sqlwork.com\), May 17, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean Nolan

    Trap "connection pool" errors

    Sean Nolan, Jul 11, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    395
    David Browne
    Jul 11, 2003
  2. Andrew Banks

    Trap all errors

    Andrew Banks, Apr 22, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    421
    Rick Spiewak
    Apr 23, 2004
  3. Rajeev Tipnis

    Handling Errors in Large File Uploads

    Rajeev Tipnis, Nov 10, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    424
    Rajeev Tipnis
    Nov 10, 2004
  4. Rolf Kemper

    Trap run time errors in XSLT

    Rolf Kemper, Oct 20, 2004, in forum: XML
    Replies:
    0
    Views:
    475
    Rolf Kemper
    Oct 20, 2004
  5. Peter A. Schott

    Best way to trap errors in ftplib?

    Peter A. Schott, Jan 11, 2005, in forum: Python
    Replies:
    1
    Views:
    326
    Mark McEahern
    Jan 12, 2005
Loading...

Share This Page