开发者

filepath of uploaded file in asp.net mvc 2

i am trying to get the filepath for my uploaded file. Is there a way to get it?

    <%= Html.BeginForm("Upload","Home",FormMethod.Post,new { enctype = "multipart/form-data" }) %>
<%{ %>

<input type="file" id="upload" name="upload" />

<button id="btnUpload">
    upload</button>

<%} %>

  [HttpPost]
    public ActionResult Upload()
    {
        HttpPostedFileBase s开发者_高级运维electedFile = Request.Files["upload"];


        //how do i get the full filelocation here?

        return View();
    }


At the point where your comment is the file is not saved - its simply a stream of bytes.

You can access the stream of bytes directly using the InputStream property, or you can save the file to some path using the SaveAs method:

selectedFile.SaveAs(someFile);

For more details see the documentation


If the browser sends the full path of the file, it's in the FileName property. However, most browsers only sends the file name nowadays, as the full file path is useless to the server, and only exposes information about the client unnecessarily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜