views:

53

answers:

2

i am trying to test to see if i get an error if i upload more than 3mb file size but instead i get the IE error (see below)

here is the code i have. - what i want is if the user try to upload more than 3mb file size display an error.

 if (fUpload.HasFile)
 {
   // Get the size in bytes of the file to upload.            
   int fileSize = fUpload.PostedFile.ContentLength;
  // Allow only files less than 3145728 bytes (approximately 3 MB) to be uploaded.
  if (fileSize > 3145728) //if (fUpload.PostedFile.ContentLength <= 3072) 
  {
     ..............
     .............
  }
  else
  {
    // Notify the user why their file was not uploaded.                
    this.lblStatus.Text = "Your file was not uploaded because it exceeds the 3 MB size limit.";
  }
}

<system.web>
    <httpRuntime maxRequestLength="3145728" />


Internet Explorer cannot display the webpage
This problem can be caused by a variety of issues, including: 

•Internet connectivity has been lost.
•The website is temporarily unavailable.
•The Domain Name Server (DNS) is not reachable.
•The Domain Name Server (DNS) does not have a listing for the website's domain.
•There might be a typing error in the address.
•If this is an HTTPS (secure) address, click Tools, click Internet Options, click Advanced, and check to be sure the SSL and TLS protocols are enabled under the security section.
A: 

You're doing this on server side. This means the file already has been started to upload to the server. I couldn't find a solution too and I don't know if there is one for this issue.

ibram
how it will start to upload without executing the code? i have breakpoint but it never break there
Abu Hamzah
try to upload a tiny file to see if this works
ibram
It works for small file, but for big size file its not even executing the code it just display ie error:......strange
Abu Hamzah
A: 

here is how i fix it:

By Default, you should be able to upload a file upto 4MB and MaxRequestLength is in Kilo Bytes. So, Default value is 4096KB. If you try to upload the file with size over 4MB, you will get an error. So, Increase that to some 25Mb or a large number. Then you should be able to track file size in your code.

<httpRuntime maxRequestLength="2097151" executionTimeout="3600"/>
Abu Hamzah