How to get the application specific data folder (ProgramData)?

前端 未结 2 614
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 18:02

I need to read and write files that contain application specific data, shared between all the users.

I tried to use Environment.GetFolderPath(Environment.Speci

2条回答
  •  抹茶落季
    2021-01-17 18:53

    Does it exist a system like Path.GetDirectoryName(Application.UserAppDataPath), which will give me the exact folder to write, according to my application name and version?

    No it doesn't exist, at least when running on Windows 7 (don't know about Windows 8/ WinRT/ Windows Store apps). Feasible solution is just to concat Environment.GetFolderPath(...) output with a custom path for your application. Typically, to reduce chances of clashing, that could be something like YourOrganization\YourApplication, or YourFullName\YourApplication, possibly also appending version.

    Or is ProgramData not the right place to do that.

    That is the right place to store application-wide information on disk. Information related to your application and different for each Windows user logging on the machine should go instead in \AppData\Roaming\..., or \AppData\Local\....

    Beware: as somebody already mentioned in comments, normally one needs administrator rights in order to work inside C:\ProgramData..., hence you would need to prepare a setup project that, during install phase, would create the folder inside ProgramData and give the right permissions.

提交回复
热议问题