Combining paths in .Net

5 04 2009

Whenever you are combining paths using Path.Combine(path1, path2), watch out for a subtle but deadly pitfall.

path1 should not have a front slash at the end and path2 should not have a front slash in the beginning. Things get really bad otherwise. I have realized this after wasting 5-6 hours of precious weekend sleep. I can’t help cussing myself, because I have a feeling that I had made this mistake before. @#$@#!$@#$%@#!@#@!$. 🙂

i.e.
string path1 = "c:\\tempdir";
string path2 = "subdir\\";
path3=Path.Combine(path1, path2)
/*path3 = c:\\tempdir\\subdir\\*/

But,

string path1 = "c:\\tempdir";
string path2 = "\\subdir\\";
path3=Path.Combine(path1, path2)
/*path3 = \\subdir\\*/

In my defense, I strongly feel that the library function should have taken care of this subtle variation. (Blame .Net 🙂 )

Anyways, find more information about this function here.





Windows mobile device platform not found

1 03 2009

If you are trying to load a windows smart device project set to .Net CF v3.5 in Visual Studio 2005, you might get this error message:

the project could not be opened because it refers to a device plaform that does not exist in your datastore

The reason being VS 2005 cannot work with .NET CF v3.5.

The workaround is to set project file’s .NET CF target framework to v2.0. i.e.

<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>

Sources:

  1. http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/f51d6fdb-2758-4b60-9527-149a18498481/
  2. http://groups.google.com/group/microsoft.public.pocketpc.developer/msg/8df085eaffb916a5