file upload problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    file upload problem

    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.
    [color=blue]
    >-----Original Message-----
    >Assuming you use the HTMLInputFile Control to choose your
    >file to upload then you can do something like this,
    >
    >HttpPostedFi le file = fileUpload.Post edFile;
    >int fileLen = file.ContentLen gth;
    >
    >fileUpload is the HTMLInputFile control name ...
    >
    >Thanks,
    >-Shan
    >
    >
    >
    >[color=green]
    >>-----Original Message-----
    >>I am trying to upload a file to the webserver through my
    >>asp.net application. The file upload works fine for[/color][/color]
    files[color=blue][color=green]
    >>below 50 MB size because i have set the maxrequestlengt h
    >>property of the <httpruntime> in the machine.config file
    >>as 51200KB. whenever the user tries to upload a file[/color]
    >which[color=green]
    >>is more than 51200KB then, a blank page with DNS error[/color][/color]
    is[color=blue][color=green]
    >>shown as soon as the user hits the submit button.
    >>I want to be able to display an error message to the[/color][/color]
    user[color=blue][color=green]
    >>if the file size is greater than 50 MB. How do i catch
    >>this error? I have tried using the try catch block in[/color][/color]
    the[color=blue][color=green]
    >>submit button onClick() event, but no use. Please post[/color][/color]
    me[color=blue][color=green]
    >>detailed answer.
    >>Thanks in advance.
    >>[/color][/color]

  • John Soulis [MSFT]

    #2
    RE: file upload problem

    Try to catch the exception in the Application_Err or event handler in
    the global.asax file

    Code:
    =====

    Dim AppEx As Exception = Server.GetLastE rror()
    If AppEx.Message.C ompareTo("Maxim um request length exceeded.") = 0 Then
    'this is an overlimit upload
    'clear the error out
    Server.ClearErr or()
    'redirect to my error page
    Response.Redire ct("errorpage.a spx")
    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
    Use these online forms to report copyright and trademark infringement to Microsoft Legal. Infringement notices must comply with the Digital Millennium Copyright Act.


    Comment

    • Guest's Avatar

      #3
      RE: file upload problem

      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.redire ct, 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.
      [color=blue]
      >-----Original Message-----
      >Try to catch the exception in the Application_Err or event[/color]
      handler in[color=blue]
      >the global.asax file
      >
      >Code:
      >=====
      >
      >Dim AppEx As Exception = Server.GetLastE rror()
      >If AppEx.Message.C ompareTo("Maxim um request length[/color]
      exceeded.") = 0 Then[color=blue]
      >'this is an overlimit upload
      >'clear the error out
      >Server.ClearEr ror()
      >'redirect to my error page
      >Response.Redir ect("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[/color]
      confers no rights.[color=blue]
      >Use of included script samples are subject to the terms[/color]
      specified at[color=blue]
      >http://www.microsoft.com/info/cpyright.htm
      >
      >.
      >[/color]

      Comment

      • John Soulis [MSFT]

        #4
        RE: file upload problem

        Does the "If" statement execute?


        Regards,
        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
        Use these online forms to report copyright and trademark infringement to Microsoft Legal. Infringement notices must comply with the Digital Millennium Copyright Act.


        Comment

        Working...