File Upload ASP.NET MVC 3.0

后端 未结 21 1027
无人共我
无人共我 2020-11-22 01:09

(Preface: this question is about ASP.NET MVC 3.0 which was released in 2011, it is not about ASP.NET Core 3.0 which was released in 2019)

I want to

21条回答
  •  别那么骄傲
    2020-11-22 01:44

    In the view:

    while the following code in the controller:

    public ActionResult Upload()
    {
        foreach (string file in Request.Files)
        {
           var hpf = this.Request.Files[file];
           if (hpf.ContentLength == 0)
           {
                continue;
           }
    
           string savedFileName = Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory, "PutYourUploadDirectoryHere");
                    savedFileName = Path.Combine(savedFileName, Path.GetFileName(hpf.FileName));
    
            hpf.SaveAs(savedFileName);
        }
    
        ...
    }
    

提交回复
热议问题