...the way I did that - learning through examples...

понедельник, 4 января 2010 г.

File upload sample



In ASP.NET websites you can upload file on server using the FileUpload web UI control.
(You can drag and drop the control from the Toolbox on the Web page in Design mode.)
The user specifies the file to upload by selecting the file by clicking the Browse button, and then locating it in the Choose File dialog box.
The FileUpload control does not automatically save a file to the server after the user selects the file to upload. You must provide a button that the user clicks to upload the file, in our sample it will be "Upload" button. Here is a code of the Upload button handler from our sample:
if (FileUpload1.HasFile)                          //  check whether the selected file
{
string path = @"C:\Received Files\"; // This specifies the path to the destination
path += FileUpload1.FileName; // add the file name to the path
FileUpload1.PostedFile.SaveAs(path); // ... and save
Label1.Text = FileUpload1.PostedFile.ContentLength.ToString() + " Bytes saved";
}
else
{
Label1.Text = "You have not selected a file to upload";
}

All our simple samples available as Microsoft Visual Studio 2008 website projects.
You can DOWNLOAD this File upload sample project from Rapidshare.

1 комментарий: