2

For dot net programs, where is the "right" place to store serialized data?

In the /user/username folder? Program Files/MyAppName/? Someplace else?

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
MrGibbage
  • 2,644
  • 5
  • 39
  • 50
  • 1
    If different users store different data then it makes sense to store it in their user account rather than in Program Files. – Sam Leach Aug 20 '13 at 12:50
  • 1
    Depends on what the data represents, what its context of use is, how big it is, how frequently it is used, etc. Provide more info on what you want to achieve for good answers. – Alex Aug 20 '13 at 12:50
  • I did not search for application settings because this was more about application data, not the settings. It can be a gray area sometimes. Sorry for the duplicate. – MrGibbage Aug 20 '13 at 13:00

2 Answers2

1

I'd say it depends on what type of date you're looking to store. If it's user specific date then I would suggest using the path returned by

Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);

If it's not user specific data, that is, it's data shared by all users of your program then storing it within a folder under your installation path is probably more appropriate.

chris.house.00
  • 3,273
  • 1
  • 27
  • 36
  • I respectfully disagree with your closing statement; it is not recommended that machine-specific data be stored in the installation path. Windows provides a "Common Application Data" location for such data. The installation path (i.e. "Program Files" folders) are intended to store *only* application files. – BTownTKD Aug 20 '13 at 13:03
1

This blog post from Microsoft's Pat Altimore suggests a number of locations, depending on what type of data you are trying to store.

.NET provides special Enum values which you can pass into System.Environment.GetFolderPath, to get the desired 'special' folder.

In short:

  • If it's user-specific data, use SpecialFolder.ApplicationData.
  • If it's machine-specific data, use SpecialFolder.CommonApplicationData.

For the machine-specific data, you will probably also need to run the program as administrator, otherwise you won't have write-access to that location.

BTownTKD
  • 7,911
  • 2
  • 31
  • 47