Click here to Skip to main content
15,881,852 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

Restrict the size of file uploads in ASP.NET

Rate me:
Please Sign up or sign in to vote.
5.00/5 (8 votes)
29 Jul 2011CPOL 39.4K   4   4
Specific directories rather than entire application: For individual uploader:int maxSize = 2097151;if (FileUpload1.HasFile &&...

Specific directories rather than entire application:


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

For individual uploader:


C#
int maxSize = 2097151;
if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentLeng­ th <= maxSize)
{
   //put some logic

}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Singapore Singapore
A life-long-learner, maker and soft music fan. Likes building things to solve problems. Years of successful records serving mid and large scale .NET applications in domestic and international client environment. Expertise in different areas of software development life cycles and Software Architecture.

Always looks for new technology and loves to get hands dirty Smile | :)

Comments and Discussions

 
Questionlogic Pin
Diya Ayesa23-Sep-13 12:41
Diya Ayesa23-Sep-13 12:41 
GeneralMy vote of 5 Pin
Maksud Saifullah Pulak26-Feb-13 20:45
Maksud Saifullah Pulak26-Feb-13 20:45 
GeneralRe: My vote of 5 Pin
Monjurul Habib27-Feb-13 8:44
professionalMonjurul Habib27-Feb-13 8:44 
GeneralRe: My vote of 5 Pin
Diya Ayesa23-Sep-13 12:41
Diya Ayesa23-Sep-13 12:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.