1

Just a quick question, I have a path,

"../../../../Items/Image/rise.png"

I want to retrieve it's full path as

C:\MyWeb\Items\Image\rise.png

How do I do it in C#,

Server.MapPath() does not recognize it.

4
  • Path is on the server or the client? Jun 29, 2011 at 8:35
  • @Jackson Pope, at Server
    – 41K
    Jun 29, 2011 at 8:36
  • 4
    @down voter, care to answer or at least give the reason.
    – 41K
    Jun 29, 2011 at 8:38
  • Is the path relative to a page?
    – onof
    Jun 29, 2011 at 8:57

2 Answers 2

2

If the path is relative to the current page, you can use Page.MapPath()

http://msdn.microsoft.com/library/system.web.ui.page.mappath.aspx

0
1

You want:

using System.IO;

Path.GetFullPath("../../../../Items/Image/rise.png");
3
  • Sorry, that does not work, it results in C:\Program Files\Items\Image\rise.png
    – 41K
    Jun 29, 2011 at 8:42
  • @41K: It works based on the current directory (as do the ..s). Where is the application you're coding running from? Jun 29, 2011 at 8:48
  • +1 for your attempt, but still I am not getting result as expected. Actually I am debugging, When I set Environment.CurrentDirectory=HttpContext.Server.MapPath("~") and called your method, the result is changed but it is still not expected, I am getting "C:\Users\dev\Items\Image\rise.png"
    – 41K
    Jun 29, 2011 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.