使用HttpPostedFileBase获取不同的路径

fro*_*sty 1 asp.net asp.net-mvc-3

请参阅以下代码.我正在上传文件,但是我从不同的浏览器中获得了不同的结果.

Firefox var path ="about.restaurant.jpg"

但在ie6 path ="D:\ dev\xxxxx\xxxxx\xxxxx\Website\images\about.restaurant.jpg"

 foreach (string file in Request.Files)
 {
        var hpf = Request.Files[file] as HttpPostedFileBase;
        var path = hpf.FileName;
 }
Run Code Online (Sandbox Code Playgroud)

我在MVC2中遇到过这个问题.刚升级到MVC3.存在同样的问题.

<form action="/Product/SaveUploadImage" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<input type="submit" value="Save" class="button" />
</form>
Run Code Online (Sandbox Code Playgroud)

fro*_*sty 5

好吧,我明白了.所以有方法可以解决所有这些问题

Path.GetFileName(hpf.FileName)