编程语言
首页 > 编程语言> > c# – 从HttpPostedFileBase获取文件路径

c# – 从HttpPostedFileBase获取文件路径

作者:互联网

我正在使用ASP.NET MVC 4,我正在尝试获取上传文件的路径以便打开和操作它.这就是我的进展方式:

调节器

public ActionResult Bulk(HttpPostedFileBase file)
{
    FileStream fs = System.IO.File.Open(Server.MapPath(file.FileName), 
                                         FileMode.Open, FileAccess.Read);

    return RedirectToAction("Index");
}

视图

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

    @using (Html.BeginForm("Bulk", "Bulk", null, FormMethod.Post, new 
                                          { enctype = "multipart/form-data" }))
    {
        @Html.ValidationSummary(true)

        <fieldset>
            <p>
                <input type="file" name="file"/>
            </p>
            <div class="form-actions">
              <button type="submit" class="btn btn-primary">Create</button>
            </div>
        </fieldset>
    }

当我这样做时,我得到一个错误,上面写着…找不到路径的一部分……

如何获取文件实际所在的路径?

解决方法:

无法评论,因为我没有足够的声誉……

标签:c,asp-net-mvc,file-upload,filepath,httppostedfilebase
来源: https://codeday.me/bug/20190624/1283175.html