AsyncFileUpload is an ASP.NET AJAX Control that allows you asynchronously upload files to server. You can save the file by calling the SaveAs () method in a handler.
AsyncFileUpload Properties:
· FileName - Gets the name of a file on a client to upload using the control.
· HasFile - Gets a bool value indicating whether the control contains a file.
· OnClientUploadComplete - The name of a javascript function executed in the client-side after the file successfully uploaded
· OnClientUploadError - The name of a javascript function executed in the client-side if the file uploading failed
· OnClientUploadStarted - The name of a javascript function executed in the client-side on the file uploading started
· PostedFile - Gets a HttpPostedFile object that provides access to the uploaded file.
· ThrobberID - ID of control that is shown while the file is uploading.
Code:
<%-- ScriptManager control manages client script for AJAX enabled ASP.NET pages.This enables partial-page rendering and Web-service calls.You have to used this if you want to use ajax control toolkit--%>
Step1: write these code on aspx page we add ajax control and one label
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<%-- Add the AsyncFileUpload control which acces the file in asynchronous way--%>
<cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server" CompleteBackColor="#66CCFF" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" OnLoad="AsyncFileUpload1_Load"
OnUploadedFileError="AsyncFileUpload1_UploadedFileError" UploadingBackColor="#CCCCFF" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
Step2: write the code on event load of ajax control
protected void AsyncFileUpload1_Load(object sender, EventArgs e)
{
if (AsyncFileUpload1.HasFile) // Check the file is exist or not by using HasFile properties
{
AsyncFileUpload1.SaveAs(Server.MapPath("~/UploadedFile/" + AsyncFileUpload1.FileName)); // Save the file here
}
}
Run the project

When you click Browse button then Browse window will open

Choose the file and click on open button

File is asynchronously uploaded whenever file is selected.
Leave a Comment