tags:

views:

48

answers:

1
string basepath = @"C:\somefolder\subfolder\bin"; // is defined in runtime
string relative = @"..\..\templates";

string absolute = Magic(basepath, relative); // should be "C:\somefolder\templates"

Can you help me with Magic method? Hopefully not too complicated code.

Is there the "Magic" method in .NET Framework?

+5  A: 

If you look at the Path class there are a couple of methods which should help:

Path.Combine

and

Path.GetFullPath

So:

string newPath = Path.Combine(basepath, relative);
string absolute = Path.GetFullPath(newPath);

Although the second step isn't strictly needed - it would give you a "cleaner" path if you were printing out say.

ChrisF
Nice! `Path.GetFullPath(Path.Combine(basepath, relative))` returns what I need.
SergeanT