0

I have gone through many discussions on multiple forums where people were discussing about how CommonAppDataFolder can be used to store per-machine files.

My application has a requirement where I need to store an XML file is a shared location such that all users running my application can read/write to that file.

I understand that CommonAppDataFolder (C:\ProgramData for Windows 7) allows admins to have read access but doesn't allow standard users to write to the file.

One of the solutions I came across is to change the permissions of the application folder in CommonAppDataFolder to allow read/write for all users.

Is this the best way to achieve my requirement or is there a better way suggested by Microsoft?

naren.katneni
  • 275
  • 1
  • 4
  • 10
  • Shared location in that they are all writing/reading to the _same_ file or each user will have their own individual file? – Aaron McIver Dec 20 '12 at 16:41
  • It is a single file shared by all users. – naren.katneni Dec 20 '12 at 16:43
  • Why would you not use a database in this instance then? If these settings are meant to be shared, having a copy on each machine doesn't make much sense to me. – Aaron McIver Dec 20 '12 at 16:43
  • I need these settings to connect to the database in the first place. And there are also terminal specific settings that can't go into the database. – naren.katneni Dec 20 '12 at 16:48
  • I'm confused, why are you not using [Application and User settings](http://msdn.microsoft.com/en-us/library/aa730869(VS.80).aspx#settingscs_topic2)? Use the Application settings for just that, Application settings and then use the database for data you want shared at runtime across the application. Creating your own XML file and the path you seem to be going down is not making sense to me. – Aaron McIver Dec 20 '12 at 17:05
  • Connectionstring to the database is in the config file and that may be modified by users running the application. – naren.katneni Dec 20 '12 at 17:38

1 Answers1

1

I suggest you to use: Environment.SpecialFolder.CommonDocuments.

e_ne
  • 8,340
  • 32
  • 43
  • This xml file contains appSettings for the application. Is it advisable (common practice) to store such files in common documents? – naren.katneni Dec 20 '12 at 16:37
  • 1
    If it's required to make them available to all users and you can't grant admin access to the `C:\ProgramData` folder, yes. Otherwise, `ApplicationData` is advised. You can refer to: http://blogs.msdn.com/b/patricka/archive/2010/03/18/where-should-i-store-my-data-and-configuration-files-if-i-target-multiple-os-versions.aspx – e_ne Dec 20 '12 at 16:42
  • I will be having a single file access by all users rather than each one having a copy in their respective `ApplicationData` From the link you posted, my file can be categorized as `Per machine configuration data`. But it doesn't give write permission to all users. – naren.katneni Dec 20 '12 at 16:46
  • And that's exactly why I suggested `CommonDocuments`. – e_ne Dec 20 '12 at 16:47