public static string SafePathCombine(string dir, string fileName)
if (Path.GetFileName(fileName) != fileName)
throw new Exception("'fileName' is invalid!");
return Path.Combine(dir, fileName);
public static void Main()
Console.WriteLine(SafePathCombine(@"C:\path\to\folder", @".."));