Upload large file using AjaxFileUpload Control with client-side chunking

With the latest release of AjaxControlToolkit you can upload large file (more than 3GB) with client-side chunking. Code is still simple as it was earlier.

Add ToolkitScriptManager & AjaxFileUpload control on page

<ajaxToolkit:ToolkitScriptManager runat="server" />  
<ajaxToolkit:AjaxFileUpload ID="AjaxFileUploader" OnUploadComplete="AjaxFileUploader_UploadComplete" runat="server" />

On UploadCompleter event set the target folder location to save file.

protected void AjaxFileUploader_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
     AjaxFileUploader.SaveAs(MapPath("~/UploadedFiles/" + e.FileName));
}

To support Large files to be uploaded, need to modify Web.config. In Web.config need to add “maxRequestLength” and “maxAllowedContentLength”.

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxRequestLength="42949672" />
    <pages>
      <controls>
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
      </controls>
    </pages>
  </system.web>
<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
    </handlers>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="4294967295"/>
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

Now run the page and upload large file data. (if you are using Chrome click F12 to see file is uploading with chunks)

http://www.dotnetworm.com/Media/Default/009/AjaxFileUpload.png

Make sure you have downloaded latest AjaxToolkit from:http://ajaxcontroltoolkit.codeplex.com/ also you can install using NuGet command in Visual Studio 2010/12 using command “INSTALL-PACKAGE AJAXCONTROLTOOLKIT” also its mandatory to have “UploadedFiles” folder in Application root to run this application.

Supported version .net 4.0 and 4.5


2 Comments

Add a Comment