ASP文件上载控件在尝试上载多个文件时仅上载一个文件

时间:2018-01-14 17:17:14

标签: .net file-upload

我正在尝试使用以下代码上传多个文件。但由于某种原因,只上传了一个文件。

------。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";
        }

    }

1 个答案:

答案 0 :(得分:0)

更改

postedFile.SaveAs(@&#34; D:\ DesignFilesLocaion \&#34; + FileUpload1.FileName);

postedFile.SaveAs(@&#34; D:\ DesignFilesLocaion \&#34; + postedFile.FileName);