开发者

Server.MapPath gives wrong path, exception "The given path's format is not supported" when running on IIS server?

Currently, I'm using the codes below to save a file to a directory on my website.

//save the file to the server
String savePath = Server.MapPath("..\\temp\\") + file;
FileUpload.PostedFile.SaveAs(savePath);

When I'm running the application on my computer, it returns the path:

"E:\dotnet\Project\Implementation\Source Code\Project\Project.UI\temp\Sample.csv"

Howev开发者_运维技巧er, when running on a real server, it throws exception:

System.NotSupportedException: The given path's format is not supported.

The expected path that I would like to have is "C:\inetpub\wwwroot\Project\temp".

Am I doing things correctly or not? If not then can someone explain to me the correct way to do this?


Server.MapPath maps a virtual path to a physical one on the server. If you replace your backslashes with forward-slashes you should be ok:

Server.MapPath("../temp/")

You can also use the root relative path:

Server.MapPath("~/temp/");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜