This control is used to upload a file and save file to a specific location using some properties.
A typical File Upload Control is constructed in the following manner:
<asp:FileUpload ID="FileUpload1" runat="server" />
For an Example of using FileUpload control and to save on local computer.
I am using extra button control and one label control.
.aspx
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Upload" onclick="Button1_Click" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
.cs
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
try
{
FileUpload1.SaveAs("C:\\Uploads\\"+FileUpload1.FileName);
Label1.Text = "File name: " +
FileUpload1.FileName + "<br/>" +
FileUpload1.PostedFile.ContentLength + " kb<br/>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
catch(Exception ex)
{
Label1.Text = ex.Message.ToString();
}
}
else
{
Label1.Text = "You have not added a file";
}
}
You can check whether your file uploaded to your local folder or disk.
If you see your file that’s it you are done with this control.
Thanks
Emmaneale Mendu
Web Developer
ASP Standard Controls
- ASP Label Control
- ASP TextBox Control
- ASP Button Control
- ASP Link Button Control
- ASP ImageButton Control
- ASP HyperLink Control
- ASP DropDownList Control
- ASP ListBox Control
- ASP CheckBox Control
- ASP CheckBoxList Control
- ASP RadioButton Control
- ASP RadioButtonList Control
- ASP Image Control
- ASP ImageMap Control
- ASP Calendar Control
- ASP Table Control
- ASP BulletedList Control
- ASP Hidden Control
- ASP Literal Control
- ASP AdRotator Control
- ASP Panel Control
- ASP PlaceHolder Control
- ASP FileUpload Control
- ASP UserControl
- ASP Custom Control
Random Tips and Tricks
Thursday, October 7, 2010
Subscribe to:
Post Comments (Atom)
2 comments:
its very helpfull.
it is very excellent blog and useful article thank you for sharing with us , keep posting learn more Ruby on Rails Online Training India
Post a Comment