Help us to translate this website and improve this translation!
English | Castellano

How to Use the FileUpload AJAX Control

History

As long as we do not leave the page that we have uploaded the files to, we will be able to access the history with all of the information on each of the items, as long as they are not deleted.

Its use is very simple, and the example explains everything.


Add




Code.aspx
<cc1:FileUploaderAJAX ID="FileUploaderAJAX1" runat="server" MaxFiles="5" />
<asp:Button ID="Button1" runat="server" Text="Ver historial" OnClick="bt_Historial_Click" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
Code.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
   if (FileUploaderAJAX1.IsPosting)
       this.managePost();
}

private void managePost()
{
   HttpPostedFileAJAX pf = FileUploaderAJAX1.PostedFile;

   if (pf.ContentType.Equals("image/gif") && pf.ContentLength <= 5 * 1024)
       FileUploaderAJAX1.SaveAs("~/temp", pf.FileName);
}

protected void bt_Historial_Click(object sender, EventArgs e)
{
   if (FileUploaderAJAX1.historial == null)
       return;

   System.Text.StringBuilder sb = new System.Text.StringBuilder();

   sb.Append("<ul>");
   foreach (HttpPostedFileAJAX file in FileUploaderAJAX1.historial)
   {
       sb.Append("<li>");
       sb.Append("<b>"+file.FileName+"</b>: ");
       sb.Append("<ul>");

       sb.Append("<li>");
       sb.Append("FileNamesaved_As: ");
       sb.Append("<i>");
       sb.Append(file.FileName_SavedAs);
       sb.Append("</i>");
       sb.Append("</li>");

       sb.Append("<li>");
       sb.Append("ContentLength: ");
       sb.Append("<i>");
       sb.Append(file.ContentLength /1024);
       sb.Append("KB</i>");
       sb.Append("</li>");

       sb.Append("<li>");
       sb.Append("FileNameContentType: ");
       sb.Append("<i>");
       sb.Append(file.ContentType);
       sb.Append("</i>");
       sb.Append("</li>");

       sb.Append("<li>");
       sb.Append("Saved: ");
       sb.Append("<i>");
       sb.Append(file.Saved.ToString());
       sb.Append("</i>");
       sb.Append("</li>");
       sb.Append("<li>");
       sb.Append("Deleted: ");
       sb.Append("<i>");
       sb.Append(file.Deleted.ToString());
       sb.Append("</i>");
       sb.Append("</li>");

       sb.Append("</ul>");
   }
   sb.Append("</ul>");

   lb_Historial.Text = sb.ToString();
}