0

I have a wpf application. It uses SQL CE database.

I am creating sdf file in user specific AppData folder. But for individual application this will create individual sdf file's.

I don't want this thing. I just want a common database location in which any user/administrator can have read/write access permission.

Which location is preferred for such scenario?

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
  • If you are using W7 then put the DB in "C:\ProgramData". – Rezoan Sep 19 '13 at 06:13
  • @Rezoan:But i need to set permission for that as per my knowledge. Any alternative without permission? –  Sep 19 '13 at 06:17
  • Its a common Place for all application. no need of permission here. – Rezoan Sep 19 '13 at 06:25
  • @Rezoan: No it requires permission. Microsoft doesn't allow write permission for ProgramData –  Sep 19 '13 at 06:57
  • So put write permission to it for all users. – Rezoan Sep 19 '13 at 07:10
  • If you are in admin mode the it does not requires any permission to read/write. if you are under standard user then you may need write permission. So for all user give it to a write permission and put the DB here. then you can read/write it from any users. @ruparelie – Rezoan Sep 19 '13 at 07:24
  • Even the Windows Guest account can write to C:\ProgramData, so any standard user should also be able. MSDN about `SpecialFolder.CommonApplicationData`: `The directory that serves as a common repository for application-specific data that is used by all users`, so where is your problem? – Clemens Sep 19 '13 at 07:34
  • @Clemens see this thread: http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/1ca0aed9-322b-463b-b2d4-9c34aaa16cfb/access-denied-when-attempting-to-write-into-a-file-in-program-data-folder-for-win7 what do you say? – Rezoan Sep 19 '13 at 08:32
  • @Rezoan Of course you may need to explicitly grant write access to files written in a folder below C:\ProgramData, but afaik this is necessary anyway, regardless of where you write a file. – Clemens Sep 19 '13 at 08:56

2 Answers2

0
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

This gives you the root folder where all app data is shared. Create a subfolder here for your app and store the file there.

Clemens
  • 123,504
  • 12
  • 155
  • 268
user2793921
  • 463
  • 4
  • 8
  • But i need to set permission for that as per my knowledge. Any alternative without permission? –  Sep 19 '13 at 06:18
  • @ruparelia You're wrong. No permission is required. `SpecialFolder.CommonApplicationData` (which is `C:\ProgramData` since Vista) is exactly what you were asking for. – Clemens Sep 19 '13 at 07:20
  • @Clemens: I have already tried which gives me an exception: `Access Denied`. But still I will try again for it. –  Sep 19 '13 at 07:47
0

Unfortunately the common place only available and everyone will suggest is systems ProgramData directory. which is normally located under "C:\ProgramData" on vista and seven.

and for XP it is "C:\Documents and Settings\All Users\Application Data"

If your application runs under administrative mode then there is no need of read/write access permission.

But if you have planned to run the application under Standard account then you may need write permission. but it depends on System UAC.

So it is suggested to create a folder for your db under ProgramData, put your db there which suppose to use by all other app from different user and grant write/modify access permission to this folder for all users.

Rezoan
  • 1,745
  • 22
  • 51
  • I am just facing the same issue..So i think I have to give permission. –  Sep 19 '13 at 10:18