ASP.NET MVC Server.MapPath giving full path in Internet Explorer

▼魔方 西西 提交于 2019-12-20 06:17:14

问题


I am uploading a file with

var filename = Server.MapPath(Path.Combine("~/Content/UserContent", Path.ChangeExtension(newName,Path.GetExtension(attachments.FileName))));
attachments.SaveAs(filename);

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?


回答1:


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.



来源:https://stackoverflow.com/questions/13953058/asp-net-mvc-server-mappath-giving-full-path-in-internet-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!