如何将一个文件多次上传到文件夹中

我想将一个文件多次上传到文件夹中。这里我的代码...


foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)

{

    string filename = Path.GetFileName(postedFile.FileName);

    string FileExtension = Path.GetExtension(postedFile.FileName);

    for(int i = 1; i <= data.Count;i++)

    {

        FileUpload1.PostedFile.SaveAs(Server.MapPath("~/InvoiceUploads/") + "Invoice " 

        + id + "_" + i + FileExtension);

    }

}

这段代码是多次上传一个文件,但问题是只有一个文件可以完美打开,另一个文件出错,显示空文件。我不知道有什么问题?请任何人帮助我。


谢谢你。


月关宝盒
浏览 214回答 3
3回答

泛舟湖上清波郎朗

void SendFile(){&nbsp; &nbsp;foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)&nbsp; &nbsp;{&nbsp; &nbsp; &nbsp; string filename = Path.GetFileName(postedFile.FileName);&nbsp; &nbsp; &nbsp; string FileExtension = Path.GetExtension(postedFile.FileName);&nbsp; &nbsp; &nbsp; // Add a delay&nbsp; &nbsp; &nbsp; Thread.Sleep(100);&nbsp; &nbsp; &nbsp; for(int i = 1; i <= data.Count;i++){&nbsp; &nbsp; &nbsp; &nbsp; postedFile.SaveAs(Server.MapPath("~/InvoiceUploads/") + "Invoice " + id + "_" + i + FileExtension);&nbsp; &nbsp; }}}

一只斗牛犬

为什么FileUpload1.PostedFile.SaveAs?使用HttpPostedFile .SaveAs(...)来代替。foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles){string filename = Path.GetFileName(postedFile.FileName);string FileExtension = Path.GetExtension(postedFile.FileName);for(int i = 1; i <= data.Count;i++){&nbsp; &nbsp; &nbsp;postedFile .SaveAs(Server.MapPath("~/InvoiceUploads/") + "Invoice " + id + "_" + i + FileExtension);}}
打开App,查看更多内容
随时随地看视频慕课网APP