ASP.NET Upload Control (WebForms & MVC) - Upload Large Files using less RAM! (available now in v2011.1)

ASP.NET Team Blog
12 May 2011

Check out the upcoming feature of our ASP.NET Upload Control that lets your end-users upload very large files without having your web server use lots of memory (RAM). And there are other benefits too.

Watch my 'Upload Big Files' video to learn about the new feature in DXperience v2011 volume 1:

Video: ASP.NET Upload Large Files

ASP.NET WebForms & MVC!

First, you'll be happy to know that the new 'upload large files' feature will be supported by both of our ASP.NET Upload WebForms control and ASP.NET MVC Upload Extension!

New Property

A new property is being introduced for our ASP.NET Upload Control and MVC Upload Extension called UploadMode. And it has 2 modes that determine how the upload control will behave and render:

  • Standard - Current/old mode - the upload control will send a file in one request. For small files, this is fine but if the file is very large then it can stress your web server as it has to load the entire file in memory
  • Advanced - New mode - the upload control will send a file using small packets. This gives you a few benefits…

...Benefits? Yes there are some pluses to 'Advanced' mode and one small caveat.

Advanced Mode Benefits

There are major benefits that you get when using the new 'Advanced' mode for uploading:

1. Upload Large Files

Upload large (2 gigabyte) files without using a huge amount of memory on your web server because the 'Advanced' mode uploads the file in small packets. The default PackedSize is 200 kilobytes and it saves these bytes to a temporary folder on your server (default is "~\App_Data\UploadTemp\").

When the upload has finished, you can access this file using the file stream:

protected void ASPxUploadControl1_FileUploadComplete(object sender, FileUploadCompleteEventArgs e) { 
    using(Stream stream = e.UploadedFile.FileContent)  { 

Or save the file using the SaveAs method:

protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e) {
    // don’t use FileBytes with Large Files!
    // byte[] a = e.UploadedFile.FileBytes;
    string filePath = Server.MapPath("~/uploads/" + e.UploadedFile.FileName);
    // DoProcessUploadedFile(filePath);

2. Client-side Validation

The new 'Advanced' mode will validate the file size and extension on the client-side without sending files to the web server. This prevents unnecessary traffic to the web server. And to ensure proper validation and give you extra protection, our ASP.NET upload control will also perform a server-side validation check once the file has passed client-side validation.

3. Progress Bar in Medium Trust

'Advanced' mode also allows you to display the file upload progress bar even in web environments that only allow medium-trust. Learn more about 'medium-trust' ASP.NET applications from this MSDN article. In general:

Medium trust will place a number of restrictions on an application, including limiting an application’s file access to within the virtual directory where the application lives. - K. Scott Allen

4. Prevent DoS Attacks

With the 'Advanced' mode, you also don't need to set a very large 'maxRequestLength' value in your web.config file. The 'maxRequestLength' property specifies the limit for the buffering threshold of the input stream. For example, this limit can be used to prevent denial of service (DoS) attacks that are caused by users who post large files to the server.

Silverlight Required

The small caveat to the new 'Advanced' mode is that it requires Silverlight (version 3 and above) to render the upload control. This will require your end-users to have the Microsoft Silverlight plugin installed in their browsers. And we still provide the 'Standard' mode which uses standard HTML.

We chose to use Silverlight so you can quickly deliver to you a robust, proven solution for uploading large files. And by using Silverlight in the 'Advanced' mode, you get more benefits.

Available Now In v2011 vol 1

The new 'Advanced' mode feature of our ASP.NET Upload WebForms control and MVC Extension is available now with the DXperience v2011 volume 1 release.

What do you think of the slick new features in our ASP.NET upload control? Drop me a line below with your thoughts. Thanks!

DXperience? What's That?

DXperience is the .NET developer's secret weapon. Get full access to a complete suite of professional components that let you instantly drop in new features, designer styles and fast performance for your applications. Try a fully-functional version of DXperience for free now:

Follow MehulHarry on Twitter

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.