Welcome to MSDN Blogs Sign in | Join | Help

MelSam's Blog

Mel Sampat on Windows Mobile
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.

Posted: Wednesday, July 26, 2006 1:02 AM by MelSam

Comments

Please tell me why... said:

Can you please tell me why my Windows Mobile 5.0 Mio A701 keeps locking up and I always have to battery reset WINDOWS MOBILE at least once a day ?

Why is it so UNSTABLE.
# July 26, 2006 3:07 PM

WM5.0 usability is NON EXISTENT said:

Why is windows mobile so DIFFICULT to use as a PHONE?  Have you EVER tried using it WITHOUT a STYLUS?  Was UX ever consulted in this project?  You just shipped a crap experience.
# July 26, 2006 3:08 PM

Marc said:

The My Documents folder used to be localized in pre-Pocket PC devices (Palm-size PC) and I used to assume that too many applications by US-based developers were broken when used on localized devices (in fact many were)so that someone decided to do away with the localized folder structure.

Are you sure you want that happening again?
# August 22, 2006 3:55 AM

Genius said:

Then please tell me who was that extremely clever person who decided that System.Environment.GetFolderPath was not needed in .NET CF 1.x, forcing developers to hard code path information into their apps in the first place?
# August 22, 2006 4:34 AM

Nino.Mobile said:

Software / Hardware At long last – the MSFP update for the Motorola Q has arrived ! (via CoolSmartPhone.com
# September 4, 2006 7:52 PM

Nino.Mobile said:

Software / Hardware At long last – the MSFP update for the Motorola Q has arrived ! (via CoolSmartPhone.com
# September 4, 2006 9:16 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker