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();
}
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 selectedFile = Request.Files["upload"];
//how do i get the full filelocation here?
return View();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的评论所在的位置,文件未保存 - 它只是一个字节流。
您可以使用
InputStream
属性直接访问字节流,也可以使用SaveAs
方法将文件保存到某个路径:有关更多详细信息,请参阅文档
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 theSaveAs
method:For more details see the documentation
如果浏览器发送文件的完整路径,则它位于
FileName
属性中。然而,现在大多数浏览器只发送文件名,因为完整的文件路径对服务器来说是无用的,并且只会不必要地暴露有关客户端的信息。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.