I was working on my site transition and developing the download code when I ran into a very interesting issue while using the Development Web Server that is built into Visual Studio 2005.

Consider the following code:

string rootDir = Server.MapPath(@"~\downloads");
string rootDir2 = Server.MapPath(@"..\downloads");

 

If you are running on the development web server, the second command will fail with a message: Failed to map the path.

However, if you deploy and run the same code to a real IIS server, you will receive the following correct values back:

d:\hosting\files\test\downloads
d:\hosting\files\downloads

I am going to make an assumption that this issue is related to the way in which the Development Web Server is actually creating the virtual web server.