Wednesday, 12 August 2015

File Upload Large Files In Asp.Net Or Size Limit


If we use FileUpload Control To upload Big Or Large Files In Asp.Net,we get error message or uploading fails because of default maximum file size limit of 4mb.

we can reset this limit in web.config to enable larger file uploads.

For single application
    <system.web>  
    <httpRuntime executionTimeout="3600" maxRequestLength="512000"/>
    </system.web>

maxRequestLength is the maximum size allowed,this will allow files upto 500 mb to be uploaded.
executionTimeout is number of seconds upload is allowed before being shut down by ASP.NET, this also needs to be increased in case of very large file uploads.

We can allow large files to be uploaded in perticular folder or directory on server either by adding a new web.config file in folder or adding below mentioned code in main web.config.
     <location path="DirectoryToUploadFiles">
     <system.web>
     <httpRuntime executionTimeout="3600" maxRequestLength="512000"/>
     </system.web>
     </location>

To apply limit settings for all the applications on server we can use web.config.comments configuration file in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG

Resetting IIS Server limits
default for IIS server is 30 mb and we can reset this in web.config as mentioned below.
     <system.webServer>
        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="512000"/>
          </requestFiltering>
        </security>
    </system.webServer>