2011-05-08 109 views
0

我正在尝试获取我上传文件的文件路径。有没有办法得到它?在asp.net上传文件的文件路径mvc 2

<%= 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 selectedFile = Request.Files["upload"]; 


     //how do i get the full filelocation here? 

     return View(); 
    } 

回答

0

在您的评论是文件没有保存点 - 它只是一个字节流。

您可以直接访问使用InputStream财产字节流,也可以使用SaveAs方法将文件保存到了一些路径:

selectedFile.SaveAs(someFile); 

欲了解更多详情,请参阅该documentation

0

如果浏览器发送文件的完整路径,它位于FileName属性中。但是,大多数浏览器现在只发送文件名,因为完整的文件路径对服务器来说是无用的,并且只会公开有关客户端的不必要的信息。