Hard-coding "My Documents"? Fix Your Code

You've probably heard this warning before - don't hard-code paths such as "\My Documents". This path has changed in past versions of Windows Mobile so it is not safe to assume the directory structure. The correct way to obtain a device's My Documents path is using the SHGetSpecialFolderPath API with a CSIDL_PERSONAL parameter. In managed code you can use System.Environment.GetFolderPath with various Environment.SpecialFolder constants.

I'm reemphasizing this because of some information I found out today. We're localizing the My Documents path for various languages in the upcoming version of Windows Mobile (codename "Crossbow"). I was surprised to know that this path isn't already localized, as it should be. After all, "My Documents" doesn't mean much to a Japanese user. I'm not sure if any other folder paths will be localized at this time, but in general it's very bad practice to assume any path (e.g. \Windows, \Storage Card etc.) If you've got code that does this, fix it by using APIs such as SHGetSpecialFolderPath, FindFirstFlashCard and SHGetDocumentsFolder.

You've still got some time before "Crossbow" devices hit the market, but it's never too early to check your code for such defects.