The File Upload control displays a text box control and a browse button that enables users to select a file to upload to the server.
- AllowMultiple: Gets or sets a true or false value that specifies whether multiple files can be selected for upload, if true then it allows multiple file uploads, the default is false.
- FileBytes: Gets an array of the bytes in a file that is specified using a System.Web.UI.WebControls.FileUpload control
- FileContent: Gets a System.IO.Stream object that points to a file to upload using the System.Web.UI.WebControls.FileUpload control.
- FileName: Gets the name of a file on a client to upload using the System.Web.UI.WebControls.FileUpload control.
- HasFile: Gets a value indicating whether the System.Web.UI.WebControls.FileUpload control contains a file.
- HasFiles: Gets a value indicating whether the System.Web.UI.WebControls.FileUpload control contains a files.
- PostedFile: Gets the underlying System.Web.HttpPostedFile object for a file that is uploaded using the System.Web.UI.WebControls.FileUpload control.
- PostedFiles: Gets the collection of uploaded files.
The following are the methods of the ASP.Net File Upload control:
- AddAttributesToRender: Adds the HTML attributes and styles of a System.Web.UI.WebControls.FileUpload control to render to the specified System.Web.UI.HtmlTextWriter object.
- OnPreRender: Raises the System.Web.UI.Control.PreRender event for the System.Web.UI.WebControls.FileUpload control.
- Render: Sends the System.Web.UI.WebControls.FileUpload control content to the specified System.Web.UI.HtmlTextWriter object, that writes the content to render on the client.
- SaveAs: Saves the contents of an uploaded file to a specified path on the Web server.
Now let us demonstrate the preceding explanation by creating a sample web application as follows:
- "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 "UsingMultiUpload" or another as you wish and specify the location.
- Then right-click on Solution Explorer and select "Add New Item" and Add Web Form.
- Drag and drop one Button, a Label and a FileUploader control onto the <form> section of the Default.aspx page.
Now the default.aspx page source code will look as follows.
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Article by Vithal Wadje</title>
- </head>
- <body bgcolor="gray">
- <form id="form1" runat="server">
- <br />
- <br />
- <div style="color: white">
- <h4>Article for C# corner</h4>
- <table>
- <tr>
- <td>Select Files</td>
- <td>
- <asp:FileUpload ID="FileUpload1" runat="server" />
- </td>
- <td></td>
- <td>
- <asp:Button ID="Button1" runat="server" Text="Uplaod" OnClick="Button1_Click" />
- </td>
- </tr>
- </table>
- </div>
- <asp:Label ID="Label1" runat="server" Visible="false" ForeColor="LawnGreen" Text="Label"></asp:Label>
- </form>
- </body>
- </html>
- <asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
- protected void Button1_Click(object sender, EventArgs e)
- {
- foreach (HttpPostedFile htfiles in FileUpload1.PostedFiles)
- {
- getFileName = Path.GetFileName(htfiles.FileName);
- htfiles.SaveAs(Server.MapPath("~/UploadedFiles/"+getFileName));
- }
- Label1.Visible = true;
- Label1.Text = FileUpload1.PostedFiles.Count.ToString() + " Files Uploaded Successfully";
- }
- using System;
- using System.Web;
- using System.IO;
- public partial class _Default : System.Web.UI.Page
- {
- string getFileName;
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- foreach (HttpPostedFile htfiles in FileUpload1.PostedFiles)
- {
- getFileName = Path.GetFileName(htfiles.FileName);
- htfiles.SaveAs(Server.MapPath("~/UploadedFiles/"+getFileName));
- }
- Label1.Visible = true;
- Label1.Text = FileUpload1.PostedFiles.Count.ToString() + " Files Uploaded Successfully";
- }
- }
- Do a proper validation such as if it has a file or not of the File Upload control when implementing.
- For more details and explanation, download the Uploaded Zip file.

kiranPosted Jan 18, 2020, 3:48 PM
I want remove file name option sir
محمد صلاح الدينPosted Nov 4, 2018, 4:59 PM
What if i want to display it
Vithal WadjePosted Apr 30, 2015, 5:06 PM
thanks
Yogendra YadavPosted Apr 30, 2015, 8:59 AM
good work sir ji
Vithal WadjePosted Apr 20, 2015, 1:20 PM
send me ur sample code
Sathish GanesanPosted Apr 20, 2015, 6:08 AM
I cant Select multiple files in internet explore 8 .Please help me
Vithal WadjePosted Mar 13, 2015, 1:19 PM
thanks Shridhar Sharma sir
Shridhar SharmaPosted Feb 9, 2015, 12:48 AM
multiple files uploaded in single click really very cool.
Vithal WadjePosted Jan 12, 2015, 12:40 PM
Thanks
Humayun Kabir MamunPosted Jan 12, 2015, 4:16 AM
Nice...