Monday, 2 July 2012

Increase the size limit of posted file for FileUploadControl in Asp.Net C#

The default maximum filesize is 4MB.

Increasing the Maximum Upload Size

In Web.Config File, under <System.Web> write the follwing code:
<system.web>
  <httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
 Note: maxRequestLength is in KB's

Code-Behind Check:

if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentLength < 20480)
{
}
else
{
   LabelMsg.Text = "You cannot upload file of size greater than 20MB";
}