2

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"

However, 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?

Leo
  • 2,173
  • 6
  • 28
  • 37

1 Answers1

1

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/");
Josh
  • 44,706
  • 7
  • 102
  • 124
  • I tried your solutions that it returns the same path that I received before when running the web on local. But still have exception "The given path's format is not supported" when running on IIS. Pls help :( – Leo Nov 19 '10 at 04:10
  • never mind, I figured out the problem: write access denied in that directory! – Leo Nov 19 '10 at 04:43