Sdílet prostřednictvím


SHGetSpecialFolderPath

Paula is mentioning this during her MDC presentations but it's something all Smartphone developers should be aware of...

On Smartphone 2002 you had to store your files withing the \IPSM directory to prevent your files from disappearing upon reboot.  On Smartphone 2003 this was changed to \Storage.  In the next version, there is a good chance that this is going to change one more time (sorry).

So how can you ensure that your application is storing files in a location that doesn't disappear when the device is turned off or the battery goes dead?  Simple: don't hard code paths.

Instead of hard coding paths like \Storage and \IPSM into your application, you should always always always ask the OS where you can safely put files.  This is done by using the SHGetSpecialFolderPath API with the CSIDL_PERSONAL parameter.  Google makes it easy to find VB.NET and C# wrappers for this.

To ensure that your Smartphone applications do the right thing in the future, start using this function in your code today.

[Author: Robert Levy]

Comments

  • Anonymous
    June 22, 2006
    How to get by default Program Files directory using CFileDialog class
  • Anonymous
    December 10, 2007
    The comment has been removed
  • Anonymous
    November 23, 2008
    I have come across a similar problem where I cannot create or store into a file using WM 2003 SE. The directory just doesnt seem to have the file one I run javascript to create it. No website has any guidance or help on this topic. Any help will be extremely appreciated. Thankyou, Baker