Wednesday, May 25, 2011

Change the upload file size in ASP.NET application

Problem:


This is a scenario i faced when i worked in web application. Our application supports to upload the documents. When the user tries to upload the file more than 4MB, the browser shows error message and . Initially I did the work around, check the size of the file and notify the user to upload less than 4 MB document.

Solution

I found that thats not the correct solution. We may stop breaking the application and google the web and found a very simple solution to solve the problem.

We need to add the below line in web.config file under System.web tag
<httpRuntime maxRequestLength="5120"/>

The httpRuntime tag has the property called maxRequestLength, which is to be specified in KB. The above shows the 5 MB file can be uploaded.

If you are not specifying the httpRuntime in web.config..the default size is 4MB.

Conclusion:


With that above work around, user can able to upload more than 4 MB and we can fix the size.

Happy Coding... :)

No comments:

Post a Comment