RadUpload for ASP.NET

Saving the Uploaded Files Send comments on this topic.
Uploading Files > FileUpload control > Saving the Uploaded Files

Glossary Item Box

RadMemoryOptimization

Since Telerik RadUpload 2.0, RadMemoryOptimization is enabled for the FileUpload controls and the standard <input type=file> (file input) HTML elements.

In order to access the files, uploaded using the above controls you need to use the RadUploadContext.Current object:

  1. The RadUploadContext object provides the UploadedFiles collection containing all uploaded files in the current request when RadMemoryOptimization was enabled:

    Dim uploadContext As RadUploadContext = RadUploadContext.Current

  2. After that using the UniqueID property of the FileUpload control you can get and save its file:

    Dim file As UploadedFile = uploadContext.UploadedFiles(FileUpload1.UniqueID)
    If Not file Is Nothing Then
        file.SaveAs(Server.MapPath("~/MyFiles/" & file.GetName))
    End If

For more information and examples about the server-side API of RadUpload check Manipulating the Uploaded Files.

Example

This example demonstrates how to save the files uploaded with standard file inputs with enabled RadMemoryOptimization:

ASPX

<input type="file" runat="server" id="FileUpload1" />
<input type="file" runat="server" id="FileUpload2" />
<rad:radprogressmanager runat="server" id="RadProgressManager1" />
<asp:button runat="server" id="Button1" text="Submit" onclick="Button1_Click" />

VB.NET

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

    Dim file As UploadedFile

    file = uploadContext.UploadedFiles(FileUpload1.UniqueID)
    If Not file Is Nothing Then
        file.SaveAs(Server.MapPath("~/MyFiles/" & file.GetName))
    End If

    file = uploadContext.UploadedFiles(FileUpload2.UniqueID)
    If Not file Is Nothing Then
        file.SaveAs(Server.MapPath("~/MyFiles/" & file.GetName))
    End If
End Sub

C#

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

    UploadedFile file;

    file = uploadContext.UploadedFiles[FileUpload1.UniqueID];
    if (file != null)
    {
        file.SaveAs(Server.MapPath("~/MyFiles/" + file.GetName()));
    }

    file = uploadContext.UploadedFiles[
FileUpload2.UniqueID];
    if (file != null)
    {
        file.SaveAs(Server.MapPath("~/MyFiles/" + file.GetName()));
    }
}