Incorrect Results With Path.Combine
A good while ago I posted about using Path.Combine to combine two paths into 1 final path. For instance, if you have a folder portion you've extracted from somewhere (maybe a root path for something you're storing in the config file, like 'c:\temp') and a final filename (like 'myfile.txt', Path.Combine("c:\temp", "myfile.txt") will join the two for a resulting filename: c:\temp\myfile.txt
There are a few interesting combinations of what will and won't combine correctly, and the MSDN page for Path.Combine explains some of these. There's one condition it won't cater for properly though - if the 2nd parameter contains a leading '\', for instance '\myfile.txt', the final result will ignore the first parameter. The output of Path.Combine("c:\temp", "\myfile.txt") is \myfile.txt'. This is not the case if the 1st parameter contains a trailing '\'. See the following for more info:
string part1 = @"c:\temp";
string part2 = @"assembly1.dll";
(1) Console.WriteLine(Path.Combine(part1, part2));
(2) Console.WriteLine(Path.Combine(part1 + @"\", part2));
(3) Console.WriteLine(Path.Combine(part1 + @"\", @"\" + part2));
(4) Console.WriteLine(Path.Combine(part1, @"\" + part2));
The output of this is
(1) c:\temp\assembly1.dll
(2) c:\temp\assembly1.dll
(3) \assembly1.dll
(4) \assembly1.dll
So the moral is - check your 2nd path for a leading '\'.