1. aspx
<Asp: FileUpload ID = "fudTest" runat = "server"/>
<Asp: Button ID = "btnUpload" runat = "server" Text = "Upload" OnClick = "btnUpload_Click"/>
<Br/>
<Asp: Label ID = "lblMessage" runat = "server"> </asp: Label>
1. aspx. cs
// Upload File button
Protected void btnUpload_Click (object sender, EventArgs e)
{
// Define the Save path
String savePath = "UploadFiles ";
// Check whether a directory exists
If (! System. IO. Directory. Exists (Server. MapPath (savePath )))
{
// The Folder does not exist.
System. IO. Directory. CreateDirectory (Server. MapPath (savePath ));
}
// Upload a file
If (fudTest. HasFile)
{
Try
{
FudTest. SaveAs (Server. MapPath (savePath) + "\" + fudTest. FileName );
LblMessagelblMessage. Text = lblMessage. Text + "client path:" + fudTest. PostedFile. FileName + "<br>" +
"File name:" + System. IO. Path. GetFileName (fudTest. FileName) + "<br>" +
"File Extension:" + System. IO. Path. GetExtension (fudTest. FileName) + "<br>" +
"File size:" + fudTest. PostedFile. ContentLength + "KB <br>" +
"File MIME type:" + fudTest. PostedFile. ContentType + "<br>" +
"Save path:" + Server. MapPath (savePath) + "\" + fudTest. FileName +
"<Hr> ";
}
Catch (Exception ex)
{
LblMessage. Text = "error:" + ex. Message. ToString ();
}
}
Else
{
LblMessage. Text = "no file to upload is selected! ";
}
}
Author ls_man