Today we will learn about AjaxFileUpload Control of AJAX Control ToolKit Article Series.

As it is Ajax file upload control, which means that files uploaded to server without any Postbacks, refresh or reload of the page ad, it gives a better user experience than the server side postback file controls.

You can learn about my previous parts here:

The best features among this are that they support drag and drop functionality and also you can upload multiple files at a time with maximum size of 1(GB) of file.

Following is the features of Ajax file upload control:

  1. Supports Drag and Drop Functionality
  2. Display File Upload Progress Bar (Depend on support of HTML5 in Browser)
  3. Display the File Info like file size and name of the uploaded file.
  4. Support uploading large file size up to 1 GB
  5. Multiple File Upload support
  6. Client side file chunking

In this modern era almost every browser has a HTML5 compatibility and progress bar is just depend on it, it has a different behavior among the browsers which are either supporting HTML5 or not.

If browser has HTML5 compatible than the progress file upload bar shown in client side, if not supported then it has to wait the server to be ready to accept the file by mean s of polling.

One of the best features of AJAX File Upload Control is Drag and Drop functionality which ease us by drag from any source and drop the control panel. By means of drag and drop you can select the multiple file to be dragged. You can also select multiple file by using keyboard keys like SHIFT or Ctrl key.

Another time consuming thing is to check the file types to be allowed or restricted in code, as we need to get the extension of the file and check correspondingly with code that it supports extension or not by showing custom message in the UI. But now Ajax file upload control bring easiness by using propertyAllowedFileTypes which can check the file types that are allowed to upload. The syntax is easy you have to mention against this property by separating the file extension by comma. Like this jpg, png, gif, docx.

Another good property (MaximumNumberOfFiles) is to allow number of files to be uploaded at a time.
AJAX File upload used handlers to upload the file to the server we will discuss how to add handlers to the configuration file earlier in this article.

AJAX File upload controls the buffers to be uploaded to server by placing the files to the temporary folder and finally when file complete events raise it move the file to the destination path and if SaveAs() is used then it automatically deletes the Temporary files and move to the original destination. If SaveAs() method is not used then you have to call the AjaxFileUploadEventArgs.DeleteTemporaryData() method to delete the temporary file.

There are a Number of Properties, Events and Methods associated with this control we will learn about each one by example.
So let’s start to first handler to the configuration File which will do our task of file uploading to the server.

Setting Up the environment contains adding the handler and also the placing control item to the page.

Adding Handler to the Web Configuration

The AjaxFileUpload control uses an HTTP Handler named AjaxFileUploadHandler.axd This handler has the type AjaxControlToolkit.AjaxFileUploadHandler. You must add this handler to your Web.Config file in order for the AjaxFileUpload control to work.

Here is the code to be placed in <System.Webserver> and inside the <handlers> section.

This Configuration settings is for IIS 7 or higher.

  1. <system.webServer>
  2. <handlers>
  3. <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler,
  4. AjaxControlToolkit" />
  5. </handlers>
  6. </system.webServer>
After Configuring we place the below code to our aspx page which will show the file upload control to the browser.

Firstly we have register the Ajax control toolkit in the page.
  1. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit"%>
Then place the code of the control to the page.
  1. <ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1"OnUploadComplete="AjaxFileUpload1_UploadComplete" Mode="Auto" runat="server"
  2. />
After placing this we can view how it looks like in the browser and check its functionality to verify it is working fine.

browser

Now we will verify its functionality by uploading a file.

functionality

Now we will look deeply in to the Properties, Events and Methods.

Properties

This is all about properties now we can move into the next which is Methods.

Methods

Events

This is all from Ajax file upload control. Meet you on the next series chapter.