Since Path.Combine does not work in all cases, this is a more complicated function Path.Combine
static string GetFullPath(string maybeRelativePath, string baseDirectory) { if (baseDirectory == null) baseDirectory = Environment.CurrentDirectory; var root = Path.GetPathRoot(maybeRelativePath); if (string.IsNullOrEmpty(root)) return Path.GetFullPath(Path.Combine(baseDirectory, maybeRelativePath)); if (root == "\\") return Path.GetFullPath(Path.Combine(Path.GetPathRoot(baseDirectory), maybeRelativePath.Remove(0, 1))); return maybeRelativePath; }
Path.Combine(@"C:\foo\",@"\foo\bar") returns @"\foo\bar" , not as expected @"C:\foo\bar"
kux
source share