public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

Asp.Net 2.0 File Upload Control

Posted by Virendra Dugar on January 8, 2009

ASP.Net 2.0 comes up with a completely new File Upload Control. This is how you can declare the file upload control.
<asp:FileUpload id=”FileUpload1″ runat=”server” />

Here are some useful properties:-
FileUpload1.FileName :- Will give File Name with the full Path.
FileUpload1.PostedFile.FileName :- Will give only the file name.
FileUpload1.PostedFile.ContentLength :- will give size of the file in Bytes.
FileUpload1.PostedFile.ContentType :- will give MIME type of uploaded file, i.e. “image/gif”.

By Default, maximum allowed size for file is 4MB. To allow files larger than the default of 4MB, one need to change the web.config.There is a parameter called maxRequestLength which takes value in the KB.

<httpRuntime executionTimeout=”1000″ maxRequestLength=”1048576″/>

The maxRequestLength property dictates the size of the request made to the Web server.When you upload files, the file is included in the request.

This example changes the maxRequestLength property’s value to 1048576KB (around 1GB). With this setting in place, end users can upload 1Gb file to the server.

There is a one more property named “executionTimeout”.This property sets the time (in seconds) for a request to attempt to execute to the server before ASP.NET shuts down the request (whether or not it is finished). The default setting is 90 seconds.
The end user receives a timeout error notification in the browser if the time limit is exceeded. If you are going to permit larger requests, remember that they take longer to execute than smaller ones. If you increase the size of the maxRequestLength property, you should examine whether to increase the executionTimeout property as well.

Uploading files in ASP.NET is very inefficient.When you pick a file and submit your form, IIS needs to suck it all in and only then you have access to the properties of uploaded file(s).You can not do about the fact that you have to sit through a long upload and wait. Neither can you display a meaningful progress bar because there’s no way to know how much is transmitted at any given time.Once IIS buffers your upload, ASP.NET takes it from there.

You might receive errors when your end users upload files to your Web server through the FileUpload control in your application. These might occur because the destination folder on the server is not writable for the account used by ASP.NET. If ASP.NET is not enabled to write to the folder you want, you can enable it using the folder’s properties.


**File upload contol also works within the update panel but Postback trigger needs to be used. 

File upload within Update Panel

As you can see from the image, I have placed the file upload control in Update panel and I have used post back trigger to upload the file.

Although there are some third party controls are also available which are very handy. Check this link. This control also shows the progress while uploading the file. 



3 Responses to “Asp.Net 2.0 File Upload Control”

  1. Abhishek Hingu said

    Hi Virendra

    I have look your post its helpfull. I have follow all step which u mention in your blog but if i am set maxRequestLength to more than 20MB than with ASP.NET 2.0 framework compiler throw error that MaxRequestLength is exceed

    can you please help me on this i want to set filed upload size to 2GB. please help me

    • Hi Abhishek,

      Maximum value that you can set for a file upload control is of 2GB. As noted in blog that maxRequestLength accepts value in KB. So 1048576 means (1024 * 1024). So to set it to 2 GB, the value will be 2097152 (1024 * 1024 * 2).

      I am interested to know that how much value you are setting for 20 MB.

      Hope this helps!!!!!

  2. minhaj said


    you mentioned everything clear i am working on xp operating system… when i am uploading more than 10 mb it shows the message that exceed the value but my value is lot more than that what i mentioned…. is it the problem with my local system or what? please help me….

    thanks in advance..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: