65.9K
CodeProject is changing. Read more.
Home

Restrict the size of file uploads in ASP.NET

starIconstarIconstarIconstarIconstarIcon

5.00/5 (8 votes)

Jul 29, 2011

CPOL
viewsIcon

40095

Specific directories rather than entire application: For individual uploader:int maxSize = 2097151;if (FileUpload1.HasFile &&...

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

}