0

Is there a way to set a 'root' or a base path to then use relative paths from in C#?

So for example, say I had the path:

C:\Users\Steve\Documents\Document.txt

Could I then use this path, instead of the programs assembly, to be the base path. So this would then allow me to use something like:

..\..\Pictures\Photo.png

Thanks

Stinkidog
  • 425
  • 2
  • 7
  • 19

1 Answers1

0

why not do:

string RootPath = string.empty

#if DEBUG
    RootPath = "C:\Users\Steve\Documents\Document.txt"
#else
    RootPath = System.Reflection.Assembly.GetAssembly(typeof(MyClass)).Location;
#endif

var newPath = Path.Combine(RootPath, "..\..\Pictures\Photo.png");
JKennedy
  • 18,150
  • 17
  • 114
  • 198
  • Where I believe this would work, it's not quite in the context of what I need. However I found the top answer here to work for me. This questions is really a duplicate: http://stackoverflow.com/questions/4796254/relative-path-to-absolute-path-in-c?rq=1 – Stinkidog Oct 07 '15 at 10:54