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.

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

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

   1: <configuration>
   2:   <system.web>
   3:     <compilation debug="true" targetFramework="4.5" />
   4:     <httpRuntime targetFramework="4.5" maxRequestLength="42949672" />
   5:     <pages>
   6:       <controls>
   7:         <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
   8:       </controls>
   9:     </pages>
  10:   </system.web>
  11: <system.webServer>
  12:     <validation validateIntegratedModeConfiguration="false"/>
  13:     <handlers>
  14:       <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
  15:     </handlers>
  16:     <security>
  17:       <requestFiltering>
  18:         <requestLimits maxAllowedContentLength="4294967295"/>
  19:       </requestFiltering>
  20:     </security>
  21:   </system.webServer>
  22: </configuration>

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

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

No Comments