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

How to Use the FileUpload AJAX Control

Max Files

With the property MaxFiles we can decide the maximum number of files that the client can upload. By default, the value is 1, but it does not have an upper limit.

The property can be set in the .aspx as well as in code.

For the example, we allow 5 files at most. You test and you will see what happens when you try to upload more than 5 files. You'll see that in fact what is allowed is 5 "input files", and if we uploaded a file of a non allowed type we will have to hide it to upload more files.


Add


Code.aspx
<cc1:FileUploaderAJAX ID="FileUploaderAJAX1" runat="server" MaxFiles="5" />
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.Type == HttpPostedFileAJAX.fileType.image && pf.ContentLength <= 5 * 1024)
      FileUploaderAJAX1.SaveAs("~/temp", pf.FileName);
}