Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
swdev:dotnet:data_and_configuration_folders [2011/04/01 09:39] smayr |
swdev:dotnet:data_and_configuration_folders [2011/04/01 16:08] (current) smayr [InnoSetup] |
||
---|---|---|---|
Line 1: | Line 1: | ||
== Data and Configuration Folders == | == Data and Configuration Folders == | ||
- | Source: [[http:// | + | Source: [[http:// |
=== Where Should I Store my Data and Configuration Files if I Target Multiple OS Versions? === | === Where Should I Store my Data and Configuration Files if I Target Multiple OS Versions? === | ||
Line 11: | Line 11: | ||
Where to store application files depends on how that data is used by the application and the user. Here is a table to outline the recommended locations for user documents and configuration data. I’ve mapped the locations across OS’s in this giant table for comparison. UPDATE: The table was a little too giant for the new MSDN template. I’ve reformatted the information into sections: | Where to store application files depends on how that data is used by the application and the user. Here is a table to outline the recommended locations for user documents and configuration data. I’ve mapped the locations across OS’s in this giant table for comparison. UPDATE: The table was a little too giant for the new MSDN template. I’ve reformatted the information into sections: | ||
- | ==== Per user configuration files synchronized across domain joined machines via Active Directory Roaming ==== | + | ===== Per user configuration files synchronized across domain joined machines via Active Directory Roaming |
Configuration data files that the application uses and are unique per user. This per user data is synchronized across the domain via Active Directory. | Configuration data files that the application uses and are unique per user. This per user data is synchronized across the domain via Active Directory. | ||
Line 26: | Line 26: | ||
</ | </ | ||
- | ==== Local per user configuration files ==== | + | ===== Local per user configuration files ===== |
Configuration data files that the application uses and is unique per user. It stays local to the individual machine and is not synchronized via Active Directory. | Configuration data files that the application uses and is unique per user. It stays local to the individual machine and is not synchronized via Active Directory. | ||
Line 41: | Line 41: | ||
</ | </ | ||
- | ==== Per machine configuration data ==== | + | ===== Per machine configuration data ===== |
Configuration data files the application uses and is per machine. It is used across all users of the application. | Configuration data files the application uses and is per machine. It is used across all users of the application. | ||
Line 55: | Line 55: | ||
</ | </ | ||
- | ==== Per user “Documents” ==== | + | ===== Per user “Documents” |
“Document” type files that users create/ | “Document” type files that users create/ | ||
Line 69: | Line 69: | ||
</ | </ | ||
- | ==== Per Machine “Documents” ==== | + | ===== Per Machine “Documents” ==== |
“Document” type files that users create/ | “Document” type files that users create/ | ||
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 97: | Line 98: | ||
NULL, & | NULL, & | ||
{ | { | ||
- | printf(" | + | printf(" |
} | } | ||
Line 105: | Line 106: | ||
NULL, & | NULL, & | ||
{ | { | ||
- | printf(" | + | printf(" |
} | } | ||
</ | </ | ||
Line 111: | Line 112: | ||
The output on Windows 7 is: | The output on Windows 7 is: | ||
< | < | ||
- | SHGetKnownFolderPath FOLDERID_RoamingAppData =C: | + | SHGetKnownFolderPath FOLDERID_RoamingAppData = C: |
- | SHGetKnownFolderPath FOLDERID_Documents | + | SHGetKnownFolderPath FOLDERID_Documents |
</ | </ | ||
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. | If you are still targeting XP, you’ll need to use the legacy API SHGetFolderPath that uses CSIDL’s. | ||
Line 154: | Line 156: | ||
| | ||
{ | { | ||
- | printf(" | + | printf(" |
} | } | ||
Line 164: | Line 166: | ||
| | ||
{ | { | ||
- | printf(" | + | printf(" |
} | } | ||
</ | </ | ||
Line 170: | Line 172: | ||
The output on Windows 7 is: | The output on Windows 7 is: | ||
< | < | ||
- | SHGetFolderPath CSIDL_APPDATA | + | SHGetFolderPath CSIDL_APPDATA |
- | SHGetFolderPath CSIDL_MYDOCUMENTS =\\zaw\Mydocs\patricka\My Documents | + | SHGetFolderPath CSIDL_MYDOCUMENTS = \\zaw\Mydocs\patricka\My Documents |
</ | </ | ||
The output on XP is: | The output on XP is: | ||
< | < | ||
- | SHGetFolderPath CSIDL_APPDATA | + | SHGetFolderPath CSIDL_APPDATA |
- | SHGetFolderPath CSIDL_MYDOCUMENTS =C: | + | SHGetFolderPath CSIDL_MYDOCUMENTS = C: |
</ | </ | ||
Line 186: | Line 188: | ||
Since we are using the .NET framework, we can still use the same technique as described in the previous section. We saw the output for Windows 7. Here’s the output we get on XP: | Since we are using the .NET framework, we can still use the same technique as described in the previous section. We saw the output for Windows 7. Here’s the output we get on XP: | ||
< | < | ||
- | SpecialFolder.ApplicationData path =C: | + | SpecialFolder.ApplicationData path = C: |
- | SpecialFolder.MyDocuments path =C: | + | SpecialFolder.MyDocuments path = C: |
</ | </ | ||
Line 195: | Line 197: | ||
Think about the type of files your application is writing. | Think about the type of files your application is writing. | ||
+ | |||
+ | == Best Practices == | ||
+ | |||
+ | Store only application files in '' | ||
+ | Store share application data in '' | ||
+ | Store user data in '' | ||
+ | |||
+ | ==== Coding in C# ==== | ||
+ | Use '' | ||
+ | <code csharp> | ||
+ | string userAppData | ||
+ | string commonAppData = Envrionment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); | ||
+ | </ | ||
+ | |||
+ | ==== InnoSetup ==== | ||
+ | Set proper permissions for shared '' | ||
+ | <code inno> | ||
+ | [Dirs] | ||
+ | Name: {commonappdata}\Acme\MyApp; | ||
+ | </ | ||
+ | == Resources == | ||
+ | * [[http:// | ||
+ | * [[http:// |