Posts tagged ‘Restrict the size of file in asp.net’

Restrict the size of file uploads in ASP.NET

For Specific directories rather than entire application:

<location path="Upload">
    <system.web>
        <httpRuntime executionTimeout="9999" maxRequestLength="2097151" />
    </system.web>
</location>

For individual uploader:
int maxSize = 2097151;
if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentLeng­ th <= maxSize)
{
   //put some logic

}

		
Advertisements