Vincent Leung .NET Tech Clips

The latest tech clips from the .NET community

AsynFileUpload – from AJAX Control Toolkit

 image

AsynFileUpload Control

The second new control included in the newest release of the AJAX Control Toolkit is the AsyncFileUpload control. You can use this control to display a fancier interface for uploading files. The AsyncFileUpload control:

  • Enables you to perform file uploads without doing a postback
  • Displays a throbber images while an image is being uploaded
  • Raises both server and client events when a file upload completes or when there is an error.
  • Works inside and outside of an UpdatePanel

Admit it! The standard file upload widget that you get with HTML is boring. You can’t display a picture while a file is uploading. And, it forces you to do a postback which is bad in this new Ajax world.

<asp:UpdatePanel ID="up1" runat="server">
  <ContentTemplate>
    <h1>Add File</h1>
    File: <br />
    <cc1:AsyncFileUpload ID="AsyncFileUpload1" onuploadedcomplete="AsyncFileUpload1_UploadedComplete" runat="server" />
    <br /><br />
    Description:<br />
    <asp:TextBox ID="txtDescription" runat="server" />
    <br /><br />
    <asp:Button ID="btnSubmit" Text="Add File" runat="server" />
    </ContentTemplate>
</asp:UpdatePanel>  
public partial class TestAsnycFileUpload : System.Web.UI.Page
{
    protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        System.Threading.Thread.Sleep(5000);
        string savePath = MapPath("~/Uploads/") + Path.GetFileName(e.filename);
        AsyncFileUpload1.SaveAs(savePath);
    }
}
  

Via New AJAX Control Toolkit Release

October 24, 2009 - Posted by Vincent Leung | AJAX Control Toolkit | | 1 Comment

1 Comment »

  1. There is also a good solution from Quadroland. It allows to upload multiple images at a time. It is also can resize/rotate images before sending (save time and traffic). Works with ASP.NET
    http://quadroland.com/q_imageuploader/

    Comment by Jack | November 3, 2009 | Reply


Leave a comment