0

I am using Server.MapPath to find the path for a document uploaded to a remote server, so that I can then open it. However when using it, it is returning a relative path and so rather than searching the remote server it is searching the local machine instead.

What I am using to open the document is:

System.Diagnostics.Process.Start(Server.MapPath(Path.Combine("~/", document)));

Where "document" is the part of the path relative to the document itself, in this case "Files\2016\11\doc_name". So I want to take the path of this document, go to the top level of the site, and then find the document from there.

However I would hope that this would return a path similar to "server\inetpub\site\Files\2016\11\doc_name" but instead it is returning a path like "d:\inetpub\site\Files\2016\11\doc_name".

Can someone help me with what is the correct function to use to get the path I need?

EDIT

I have managed to fudge together the correct path using the following code:

string server = Environment.MachineName;
string path = Server.MapPath(Path.Combine("~/", documentpath));

System.Diagnostics.Process.Start(@"\\" + server + path.Substring(path.IndexOf(@"\")));

However, while I can get this to access the file when I'm running the project locally, it errors when I try to do it on the published site. As I can access it in one way, I'm assuming that it could be permissions (just to note the site is using windows authentication). Is this the most likely cause?

James Peel
  • 159
  • 1
  • 3
  • 11
  • 1
    Not clear what you trying to achieve, but MapPath behaves exactly like you observe. – Alexei Levenkov Nov 10 '16 at 13:00
  • It's currently bringing back a relative path for the file, which is leading the code to look locally for it. What I need is it to return an absolute path, including the server name, so that it looks on the remote server for the file – James Peel Nov 10 '16 at 13:41
  • Not that you are using term "relative path" in unconventional way... "d:\foo"is absolute path froe Windows point of view. – Alexei Levenkov Nov 10 '16 at 14:05
  • Yeah, I couldn't think of a better way to phrase it as technically the path it is returning is relative to the computer that you are viewing the page from, despite it being an absolute path for your local machine. – James Peel Nov 10 '16 at 14:21

0 Answers0