Asp.net MVC - 获取上传文件的完整文件名 [英] Asp.net mvc - get full file name of uploaded file

查看:495
本文介绍了Asp.net MVC - 获取上传文件的完整文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在asp.net的MVC来获得上传文件的完整文件名?![输入图像的描述在这里]

Is it possible to get full file name of uploaded file in asp.net mvc?![enter image description here]

更新
的数据只包含的文件名,但不文件路径!请参阅附加了解详情。

推荐答案

这取决于浏览器。结果
大多数浏览器(FF,铬,Safari浏览器)不发送此信息,主要是出于安全考虑。但是,它看起来好像某些版本的IE做派完整的客户端的路径。结果
这个值将被存储在的文件名的 HttpPostedFile 属性。

It depends on the browser.
Most browsers (FF, Chrome, Safari) do not send this information, primarily for security reasons. However, it appears as though some versions of IE do send the full client path.
This value will be stored in the FileName property of the HttpPostedFile.

文件名的文件应该帮助它说:

The documentation for FileName should help. It says:

文件名:客户端的文件的名称,包括目录路径

FileName: The name of the client's file, including the directory path.

在以下code, postedFile.FileName 会根据浏览器。因此,它始终只提取文件名是很重要的,而且你也可能得到幸运,并获得 clientPath 太。

In the following code, postedFile.FileName will vary based on the browser. Therefore, it's important to always extract just the filename, and you might also get lucky and get the clientPath too.

public ActionResult UploadFile(HttpPostedFile postedFile) {
    var clientPath = IO.Path.GetDirectoryName(postedFile.FileName);
    var filename = IO.Path.GetFileName(postedFile.FileName);
    ... Save the file, etc ...
}

这篇关于Asp.net MVC - 获取上传文件的完整文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆