RadUpload for ASP.NET

RadMemoryOptimization Send comments on this topic.
Uploading Files > RadMemoryOptimization

Glossary Item Box

General Information

By default, when a file is uploaded the .NET Framework stores it in the memory, thus significantly reducing the maximum possible size of the uploaded files. Sometimes, when uploading very large files, it is possible to encounter application restarts due to reaching the upper memory limit of the .NET framework.

When RadMemoryOptimization is enabled, the uploaded files are extracted from the request stream and then stored into a temporary location on the web server hard disk, thus allowing uploads of files with size up to 2GB. During the extraction process, you can monitor the progress of the upload. The temporary files are deleted at the end of each request.

How to enable RadMemoryOptimization

In order to enable RadMemoryOptimization for a specific page you need to:

  1. Register RadUploadHttpModule in the application web.config.
  2. If you want to upload files, larger than 4MB, you should configure your application.
  3. Put a RadProgressManager control on the page which will be used for file uploads.

Note: When RadMemoryOptimization is enabled on a page, the ASP.NET FileUpload controls and the Standard File Inputs will be unable to find their files automatically. You can obtain their uploaded files by using the RadUploadContext object. RadUpload is able to find its files automatically.

Important Notes

RadMemoryOptimization is not functional when the application is hosted in IIS7. Host your project in IIS5 (Windows 2000), IIS5.1 (Windows XP), IIS6 (Windows 2003) or the VisualStudio 2005 Web Development Server (FileSystem based Web Site).

RadMemoryOptimization is not compatible with the ASP.NET application trace. If you enable the application trace the server will receive only the first 30-50kB of the selected files and then the upload will hang.

RadMemoryOptimization requires ReflectionPermission in order to operate correctly. This means that in normal circumstances you will have to run your application with Full Trust permission set, unless you create custom security policy, which allows ReflectionPermission. If you are unable to set Full Trust or custom security policy, the solution is to put the RadUpload assembly in GAC.

RadUploadContext

When RadMemoryOptimization is enabled you can access all uploaded files within the current request using the RadUploadContext object. You can obtain an instance of this object using its static (shared in VB.NET) property Current. The UploadedFiles collection of this instance contains all files, uploaded within the current request, including those selected with RadUpload controls and those, selected with regular <input type=file> elements.

VB.NET

Imports Telerik.WebControls
...
Protected Sub Button1_Click(ByVal sender As ObjectByVal e As EventArgs)
    Dim uploadContext As RadUploadContext = RadUploadContext.Current
    ...
End Sub

C#

using Telerik.WebControls
...
protected void Button1_Click(object sender, EventArgs e)
{
    RadUploadContext uploadContext = RadUploadContext.Current;
    ...
}

You can find another example involving RadUploadContext in Saving the files, uploaded with FileUpload controls.