Sie sind auf Seite 1von 4

7/16/13

Restrict/Increase the size of file upload in asp.net - ASP.NET,C#.NET,VB.NET,JQuery,JavaScript,Gridview,SQL Server,Ajax,SSRS, XML examples
Follow @aspdotnetsuresh 2,600 follow ers

ASP.NET,C#.NET,VB.NET,JQuery,JavaScript,Gridview,SQL HOME ASP.NET AJAX GRIDVIEW JAVASCRIPT SQL JQUERY OOPS CONCEPTS INTERVIEW QUESTIONS Server,Ajax,SSRS, XML examples
aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code Restrict/Increase the size of file examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies By: Suresh Dasari Dec 14, 2010
Categories: Asp.net , Fileupload

TRACE MOBILE NUMBER

ADVERTISE

upload in asp.net

Introduction: Here I will explain how to increase or restrict the size of file upload in asp.net Description: I have one page that contains one file upload control to accept files from user and saving it in one folder. I have written code to upload file and saving it to folder its working fine after completion of my application my friend has tested my application like he uploaded large size file nearly 10 MB file at that time its shown the error page like the page cannot displayed. Again I have search in net I found that file upload control allows maximum file size is 4MB for that reason if we upload file size larger than 4MB we will get error page like the page cannot displayed or Maximum request length exceeded. After that I tried to increase the size of uploaded file by setting some properties in web.config file like this

<system.web> <httpRuntime executionTimeout="9999" maxRequestLength="2097151"/> </system.web> Here httpRuntime means Configures ASP.NET HTTP runtime settings. This section can be declared at the machine, site, application, and subdirectory levels. executionTimeout means Indicates the maximum number of seconds that a request is allowed to execute before being automatically shut down by ASP.NET. maxRequestLength means Indicates the maximum file upload size supported by ASP.NET. This limit can be used to prevent denial of service attacks caused by users posting large files to the server. The size specified is in kilobytes. The default is 4096 KB (4 MB). After that write the following code in aspx page

<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html> After that write the following code in code behind

protected void Button1_Click(object sender, EventArgs e) { if (FileUpload1.HasFile)

www.aspdotnet-suresh.com/2010/12/how-to-restrict-size-of-upload-file-in.html

1/4

7/16/13

Restrict/Increase the size of file upload in asp.net - ASP.NET,C#.NET,VB.NET,JQuery,JavaScript,Gridview,SQL Server,Ajax,SSRS, XML examples
{ if (FileUpload1.PostedFile.ContentLength < 20728650) { try { Label1.Text = "File name: " + FileUpload1.PostedFile.FileName + "<br>" + FileUpload1.PostedFile.ContentLength + " kb<br>" + "Content type: " + FileUpload1.PostedFile.ContentType; } catch (Exception ex) { Label1.Text = "ERROR: " + ex.Message.ToString(); } } else { Label1.Text = "File size exceeds maximum limit 20 MB."; } } } After that write the following code in web.config

<system.web> <httpRuntime executionTimeout="9999" maxRequestLength="2097151"/> </system.web> Demo

Tweet

If you like this post then Why not Join or Follow this site

If you enjoyed this post, please support the blog below. It's FREE!
Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

Subscribe by RSS
Follow @aspdotnetsuresh 2,600 follow ers

Subscribe by Email

www.aspdotnet-suresh.com/2010/12/how-to-restrict-size-of-upload-file-in.html

2/4

7/16/13

Restrict/Increase the size of file upload in asp.net - ASP.NET,C#.NET,VB.NET,JQuery,JavaScript,Gridview,SQL Server,Ajax,SSRS, XML examples

5 comments :
duggu said... can u pls tell me about sharing sql database over LAN...

March 24, 2012 at 2:17 PM Anonymous said... how we can upload large file like 100-200 mb. tnx jasraj

June 24, 2012 at 5:06 AM Anonymous said... how can i upload an image with some text data

July 24, 2012 at 11:47 PM Anonymous said... test

September 11, 2012 at 11:02 PM rupesh said... Hi Suresh, I had used ajax fileupload control to upload excel file in which i don't know the path but i want to read data in the file and i don't now the sheet name and file name Please reply for the post

December 5, 2012 at 4:25 AM

Give your Valuable Comments

Newer Post Subscribe to: Post Comments ( Atom )

Home

Older Post

Other Related Posts


www.aspdotnet-suresh.com/2010/12/how-to-restrict-size-of-upload-file-in.html 3/4

7/16/13

Restrict/Increase the size of file upload in asp.net - ASP.NET,C#.NET,VB.NET,JQuery,JavaScript,Gridview,SQL Server,Ajax,SSRS, XML examples
3 tier architecture example in asp.net with C# Asp.net insert, Edit, update, delete data in gridview Introduction to Object Oriented Programming Concepts (OOPS) in C#.net jQuery 360 Degrees Image Display Plugins Examples with Tutorial Introduction to WCF - WCF tutorial | WCF Tutorial - Windows Communication Foundation | WCF Example | WCF Sample code in asp.net 3.5 | Basic WCF Tutorial for Beginners Interview Questions in ASP.NET,C#.NET,SQL Server,.NET Framework how to insert images into database and how to retrieve and bind images to gridview using asp.net (or) save and retrieve images from database using asp.net Simple login form example in asp.net Check Username and Password availability in database Ajax M odalPopUpExtender Example to edit the gridview row values in asp.net Ajax Cascading Dropdownlist Sample with database using asp.net

www.aspdotnet-suresh.com/2010/12/how-to-restrict-size-of-upload-file-in.html

4/4

Das könnte Ihnen auch gefallen