Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:data_and_configuration_folders [2011/04/01 09:45]
smayr [Native Code]
swdev:dotnet:data_and_configuration_folders [2011/04/01 16:08] (current)
smayr [InnoSetup]
Line 88: Line 88:
  
 ===== Native Code ===== ===== Native Code =====
 +
 The best API to use if you are targeting Vista and beyond is the new SHGetKnownFolderPath. This function replaces SHGetFolderPath and has the following advantages. The best API to use if you are targeting Vista and beyond is the new SHGetKnownFolderPath. This function replaces SHGetFolderPath and has the following advantages.
  
Line 143: Line 144:
  
 ===== Native Code ===== ===== Native Code =====
 +
 If you are still targeting XP, you’ll need to use the legacy API SHGetFolderPath that uses CSIDL’s.  This API is still supported in Vista and Windows 7 and will map to the correct locations on all three versions of the OS. If you are still targeting XP, you’ll need to use the legacy API SHGetFolderPath that uses CSIDL’s.  This API is still supported in Vista and Windows 7 and will map to the correct locations on all three versions of the OS.
  
Line 196: Line 198:
 Think about the type of files your application is writing.  Are they configuration files, data files, or documents? Are they per machine or per user? Choose the appropriate location for the file type and then use the right API to get the path to that location. Chris has a great post on this topic. There is also a support article and a whitepaper that has good info on storing application data. Think about the type of files your application is writing.  Are they configuration files, data files, or documents? Are they per machine or per user? Choose the appropriate location for the file type and then use the right API to get the path to that location. Chris has a great post on this topic. There is also a support article and a whitepaper that has good info on storing application data.
  
 +== Best Practices ==
 +
 +Store only application files in ''C:\Program Files''.
 +Store share application data in ''C:\ProgramData''.
 +Store user data in ''C:\Users''.
 +
 +==== Coding in C# ====
 +Use ''Environment.SpecialFolder'' to get these folders. Example:
 +<code csharp>
 +string userAppData   = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);  
 +string commonAppData = Envrionment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
 +</code>
 +
 +==== InnoSetup ====
 +Set proper permissions for shared ''C:\ProgramData'' folder to store share database and configuration files.  The permissions should be Read, Write, Modify for user group ''Users'':
 +<code inno>
 +[Dirs]
 +Name: {commonappdata}\Acme\MyApp; Permissions: users-modify
 +</code>
 == Resources == == Resources ==
   * [[http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx|MSDN CSIDL]]   * [[http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx|MSDN CSIDL]]
   * [[http://msdn.microsoft.com/en-us/library/dd378457(v=VS.85).aspx|MSDN KNOWNFOLDERID]]   * [[http://msdn.microsoft.com/en-us/library/dd378457(v=VS.85).aspx|MSDN KNOWNFOLDERID]]