In ASP.NET FileUploader is a very lengthy process to upload files asynchronously because we need to write many lines of code. Using the Ajax AsyncFileUpload control however we can upload files asynchronously without much code. So let us learn about the AsyncFileUpload control step-by-step.
AsyncFileUpload is an ASP.Net Ajax control that allows you to asynchronously upload files to the server. The file uploading results can be checked both in the server and client sides.
The following are some of the common properties of the ASP.Net Ajax asyncFileUpload control:
- FileBytes: Gets an array of the bytes in a file.
- FileContent: Gets a System.IO.Stream object that points to a file to upload.
- FileName: Gets the name of a file on a client to upload.
- HasFile: Gets a value indicating whether the control contains a file.
- PostedFile: Gets the underlying System.Web.HttpPostedFile object for a file.
- CompleteBackColor : Control's background color on upload complete.
- ErrorBackColor: Control's background color on on error.
- UploadingBackColor: Control's background color on uploading file.
- PersistFile : Decides whether the files persist or not with true and false properties according to the PersistedStoredType.
- PersistedStoreType : Decides where to persist a file such as session or other.
The following are the methods of the ASP.Net File Upload control:
- DescribeComponent .
- "Start" - "All Programs" - "Microsoft Visual Studio 2010".
- "File" - "New WebSite" - "C#" - "Empty WebSite" (to avoid adding a master page).
- Provide the web site a name such as "UsingAsyncFileuploader" or another as you wish and specify the location.
- Then right-click on the Solution Explorer and select "Add New Item" and Add Web Form.
- Drag and drop one Button, a Label and a UsingAsyncFileuploader
control onto the <form> section of the Default.aspx page from the
Ajax Control Toolkit.
- Drag and drop scriptManager.
Write the following code for the Upload button click event to upload and save files on the server folder as in the following:
Now run the application. The UI will look such as follows:
Now click on the Browse Button and select file as in the following:
Now click on the Upload button. The following message is shown as I have set to a label control as in the following:
Now refresh the folder we created to save the files to, it will look such as follows:
Now you have seen how to upload files using the ASP.Net Ajax AsyncFileUploader.
- Do a proper validation such as if it has a file or not of the File Upload control when implementing.
- Download Ajax Control toolkit.
From all the preceding examples you have learned how to upload files using the ASP.Net Ajax AsyncFileUploader. I hope this article is useful for all readers, if you have a suggestion then please contact me.