How to get the data folder of specific applications (ProgramData)?

I need to read and write files containing application-specific data shared by all users.

I tried using Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) , but it only returns C: \ ProgramData.

My question is:

Is there a system like Path.GetDirectoryName(Application.UserAppDataPath) that will give me the exact folder for writing according to my name and version of the application?

Or ProgramData is not suitable for this.

Thanks.

+6
source share
1 answer

Is there a system like Path.GetDirectoryName (Application.UserAppDataPath) that will give me the exact folder for writing according to my name and version of the application?

No, it does not exist, at least when working in Windows 7 (I do not know about Windows 8 / WinRT / Windows Store applications). A possible solution is to simply execute the output of Environment.GetFolderPath(...) with a custom path for your application. Typically, to reduce the chance of a collision, it could be something like YourOrganization\YourApplication or YourFullName\YourApplication , possibly also adding a version.

Or ProgramData is not suitable for this.

This is a good place to store cover art on disk. Information related to your application and other for each Windows user login on the machine should go instead to <User folder>\AppData\Roaming\... or <User folder>\AppData\Local\...

Beware : as mentioned in the comments, you usually need administrator rights to work inside C: \ ProgramData ..., so you will need to prepare an installation project that during the installation phase will create a folder inside ProgramData and provide the correct permissions.

+4
source

Source: https://habr.com/ru/post/980918/


All Articles