我正在尝试使用以下代码上传多个文件。但由于某种原因,只上传了一个文件。
------。aspx代码
<asp:FileUpload ID="FileUpload1" AllowMultiple="true" runat="server" />
<asp:Button ID="Button2" runat="server" OnClick="Button1_Click" Text="Upload" />
<asp:Label ID="Label2" runat="server" Text="Label">
------。cs代码
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)
{
string fileName = Path.GetFileName(postedFile.FileName);
postedFile.SaveAs(@"D:\DesignFilesLocaion\" + FileUpload1.FileName);
}
Label2.Text = string.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count);
}
else
{
Label2.Text = "Please select file";
}
}
答案 0 :(得分:0)
更改
postedFile.SaveAs(@&#34; D:\ DesignFilesLocaion \&#34; + FileUpload1.FileName);
到
postedFile.SaveAs(@&#34; D:\ DesignFilesLocaion \&#34; + postedFile.FileName);