摘要:ASP.NET C# FILEUPLOAD 自動上傳
ASPX
<asp:FileUpload ID="FileUpload1" runat="server" onchange="this.form.btn.click();" />
<div style="display:none;" >
<asp:Button ID="btn" runat="server" Text="Button" onclick="btn_Click" />
C#
protected void btn_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
if (FileUpload1.PostedFile.FileName.Length > 0)
{
string txt = FileUpload1.FileName;
string path = Server.MapPath("~/data/XX/");
FileUpload1.SaveAs(path + FileUpload1.FileName);
}
}
}