Just take the FileUpload control from Toolbox to a Web page. The following code adds the FileUpLoad control:
Code:
<asp:FileUpLoad id="FileUpLoad1" runat="server" />
To support file upload, we need to add a Button control:
<asp:Button id="btn_upload" Text="Upload File" OnClick="btn_upload_Click" runat="server" Width="105px" />
In button click event handler, we would like to call SaveAs method of FileUpLoad control, which gets an entire path where the file will be uploaded.
Code:
protected void btn_upload_Click(object sender, EventArgs e)
{
if (FileUpLoad1.HasFile)
{
FileUpLoad1.SaveAs(@"C:temp" + FileUpLoad1.FileName);
Label1.Text = "File Uploaded: " + FileUpLoad1.FileName ;
}
else
{
Label1.Text = "No File Uploaded.";
}
} The page looks like Figure 1.
Fig ure 1. FileUpLoad control:
Bookmarks