Default.aspx
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>文件上傳測試</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="BtnUpload" runat="server" Text="上傳" OnClick="BtnUpload_Click" />
</div>
</form>
</body>
</html>
Default.aspx.cs
protected void BtnUpload_Click(object sender, EventArgs e)
{
string path = "c:\\pdfword\\";
if (FileUpload1.HasFile)
{
try
{
FileUpload1.SaveAs(path + FileUpload1.FileName);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}