Classify and store data correctly |
It is vital in any managed system that applications store their data correctly. You should ensure that your program writes its data (such as user preferences, program state, temp files etc.) to the appropriate location.
Because Windows provides a dynamic operating environment for your application, it is not always safe to make assumptions about the location of files or folders. Default storage locations may change during the runtime of your program.
The classification and appropriate storage of application and user data is a topic discussed in some detail in the data separation guidelines.
To recap, three of the most important things to remember are:
Use SHGetFolderPath to find popular shell folders. Don’t hardcode full paths like "C:\My Documents" into your application, check the path each and every time you open shell folders.
Use GetTempPath to locate appropriate storage for temporary files. The path to the Windows temp folder is obtained by calling the Win32 API GetTempPath. While it is possible to obtain the temp path by other means, note that an administrator can reconfigure the temp path at any time.
Store paths as UNC or relative to special folder CSIDLs. Instead of storing path information in the registry, read it from the system with APIs like GetTempPath and SHGetFolderPath. If you must store a path, store it as a UNC or relative path.
CSIDLs, Data Separation Guidelines, GetTempPath, SHGetFolderPath