Using the asp:FileUpLoad
to upload files works fine except the
file size does not exceed the maximum allowed. When the maximum is exceeded. I
get an error "Internet Explorer cannot display the webpage". The
problem is the try catch block doesn't catch the error so I cannot give the user
a friendly message that they have exceed the allowable size. I have seen this
problem while searching the web but I cannot find an acceptable solution.
Default file size
limit is (4MB) but you can change the default limit in a localized way by
dropping a web.config in the directory where your upload page lives. That way
you don't have to make your whole site allow huge uploads (doing so would open
you up to a certain kinds of attacks).
Just set in
web.config under <system.web> section. e.g. In the below example I am
setting the maximum length that is 2GB
<httpRuntime maxRequestLength="2097152"
executionTimeout="600" />
Please note that
the maxRequestLength is set in KB's and it can be set up to 2GB (2079152 KB's).
Practically we don't often need to set 2GB request length, but if you set the
request length higher, we also need to increase the executionTimeout.
Execution Timeout specifies
the maximum number of seconds that a request is allowed to execute before being
automatically shut down by ASP.NET. (Default time is 110 seconds.)
Now if you want to
show the custom message to user, if the file size is greater than 100MB.
You can do like..
if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentLength > 104857600)
{
//FileUpload1.PostedFile.ContentLength -- Return the size in bytes
lblMsg.Text = "You can only upload file up to 100 MB.";
}