Path.Combine Error (CompactFramework)

Cags

Well-known member
Joined
Feb 19, 2004
Messages
690
Location
Melton Mowbray, England
For some reason the following code sets the value of path as @"\Themes\Default\Image.jpg". Am I doing something stupid, does the .Net Compact Framework have bugs or what?
C#:
string path = System.IO.Path.Combine(@"\Program Files\Selection", @"\Themes\Default\Image.jpg");
 
Ive managed to solve the problem myself, but Ill post the solution incase anyone else meets this problem.

From MSDN...
If path2 does not include a root (for example, if path2 does not start with a separator character or a drive specification), the result is a concatenation of the two paths, with an intervening separator character. If path2 includes a root, path2 is returned.
The bold section is the key to this problem, unfortunately on mobile devices the root is the same as the seperator character. As such you have to remove any seperator characters that appear at the start of path2 before combining them.
 
I think that in general (at least, as far as the .Net framework is involved) a relative folder path should not start with a backslash.
 
The code returns path2 in the full .Net Framework aswell so you are probably correct. I personally cant see a reason why a preceeding seperator character would cause any specific problems, I guess its just down to standards.
 
Back
Top