<input id="FileUp" type="file" name="FileUp" class="edline" runat=server />
拖放一個按鈕控件,鍵後台代碼如下:
protected void up_Click(object sender, EventArgs e)
{
HttpPostedFile pfile = this.FileUp.PostedFile;//得到要上傳文件
string fileName, fileExtence;
fileName = System.IO.Path.GetFileName(pfile.FileName);//文件名稱
if (fileName != "")
{
fileExtence = System.IO.Path.GetExtension(fileName);//上傳文件的擴展名
string new_fileName = fileName;//給文件重新命名
pfile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("requests/") + new_fileName);//保存路徑
Label2.Text = "上傳成功!";
Label2.Visible = true;
}
}