It has been a while since I have done significant UI work for a Windows application, however, the last product I remember developing we broke almost every rule in the book with regards to storing local data on the PC. The main reason for this level of contravention was that Windows NT, and subsequently, Windows 2000 never complained. Couple that with the fact that everyone basically ran as administrator led to programmer apathy and a lack of Windows compatibility.
With the advent of Vista and the persistence of UAC we have been forced to collectively understand what we should and should not do when it comes to reading and writing application specific data, and trust me this will not go away in Windows 7. Here are my top 3 bad data storage decisions for Windows:
- Storing User and Application data in the Program Files – Now I am not talking about installation type data, but I am referring to user specific information that probably will not be shared.
- Reading and Writing from System32 – There may be a few edge cases where a read is needed but a write?
- Writing to Global registry settings – enough said…
.NET Framework has a really convenient enumerated type, Environment.SpecialFolder, which is used in Environment.GetFolderPath
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData + “\AppName”)
|MyDocuments||The "My Documents" folder.|
|MyComputer||The "My Computer" folder.|
|MyMusic||The "My Music" folder.|
|MyPictures||The "My Pictures" folder.|
|ApplicationData||The directory that serves as a common repository for application-specific data for the current roaming user.|
|CommonApplicationData||The directory that serves as a common repository for application-specific data that is used by all users.|
|LocalApplicationData||The directory that serves as a common repository for application-specific data that is used by the current, non-roaming user.|
|Cookies||The directory that serves as a common repository for Internet cookies.|
|Desktop||The logical Desktop rather than the physical file system location.|
|Favorites||The directory that serves as a common repository for the user's favorite items.|
|History||The directory that serves as a common repository for Internet history items.|
|InternetCache||The directory that serves as a common repository for temporary Internet files.|
|Programs||The directory that contains the user's program groups.|
|Recent||The directory that contains the user's most recently used documents.|
|SendTo||The directory that contains the Send To menu items.|
|StartMenu||The directory that contains the Start menu items.|
|Startup||The directory that corresponds to the user's Startup program group.|
|System||The System directory.|
|Templates||The directory that serves as a common repository for document templates.|
|DesktopDirectory||The directory used to physically store file objects on the desktop.|
|Personal||The directory that serves as a common repository for documents.|
|ProgramFiles||The program files directory.|
|CommonProgramFiles||The directory for components that are shared across applications.|
Here are a list of the members that will get you quick access to various locations on your PC, I find the top 7 or so the most useful and UAC appropriate. Here are a couple of links on Windows Compatibility and Configuring User Access Control.