ASP.NET MVC让使用Server.Mappath Internet Explorer中的完整路径 [英] ASP.NET MVC Server.MapPath giving full path in Internet Explorer
本文介绍了ASP.NET MVC让使用Server.Mappath Internet Explorer中的完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我上传一个文件
var filename = Server.MapPath(Path.Combine("~/Content/UserContent", Path.ChangeExtension(newName,Path.GetExtension(attachments.FileName))));
attachments.SaveAs(filename);
它的工作原理只是在Internet Explorer伟大它给人的完整路径C:\\用户\\ okke \\桌面\\ GEWOONEENMAP OK \\ etags.txt?而不是只说etags.txt,我怎么能解决这个问题
it works great except that in Internet Explorer it gives the full path "C:\Users\okke\Desktop\GEWOONEENMAP OK\etags.txt" instead of just saying "etags.txt", how can I fix this?
推荐答案
呼叫的 Path.GetFileName 只得到文件名如:
Call Path.GetFileName on the result to get only the file name e.g.
attachments.SaveAs(Path.GetFileName(fileName));
如果的文件名
的值将返回的文件名(带分机)的文件路径,如果它已经是一个有效的文件名,将刚刚返回相同值。
If the value of fileName
is a file path it will return the file name (with ext), if it is already a valid file name it will just return the same value.
这篇关于ASP.NET MVC让使用Server.Mappath Internet Explorer中的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文