Reputation: 453
A colleague of mine is looking for a method in System.IO that will do this:
var path1 = "c:\\temp\\foo\\bar";
var path2 = "..\\..\\foo2\\file.txt";
var path3 = Path.Combine2(path1, path2);
// path3 = "c:\\temp\\foo2\\file.txt"
Is there anything in System.IO to do this type of combining, or will he have to write his own method? I couldn't find anything.
Thanks!
Upvotes: 3
Views: 530
Reputation: 181067
This should do it;
var path3 = Path.GetFullPath(Path.Combine(path1, path2));
Upvotes: 4
Reputation: 49013
var path1 = "c:\\temp\\foo\\bar";
var path2 = "..\\..\\foo2\\file.txt";
var path3 = Path.GetFullPath(Path.Combine(path1, path2)).Normalize();
Upvotes: 9