Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

My question is :

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?

Or is ProgramData not the right place to do that.

Thanks.

like image 560
paulinodjm Avatar asked Jan 13 '15 09:01

paulinodjm


People also ask

How do I find ProgramData folder in Windows 11?

Open File Explorer from the taskbar. Select View > Options > Change folder and search options. Select the View tab and, in Advanced settings, select Show hidden files, folders, and drives and OK.

What is stored in ProgramData folder?

On the other hand, the ProgramData folder has the general program files for all users, or, as Microsoft says, "this folder is used for non-user program data." For example, antivirus programs store their settings and virus logs within this folder to be available to all users on your computer instead of storing multiple ...

How do I find the application data folder in Windows 10?

To open the AppData folder on Windows 10, 8 & 7: Open File Explorer/Windows Explorer. Type %AppData% into the address bar and hit enter. Navigate to the required folder (Roaming or Local)

What is the ProgramData folder in Windows?

ProgramData specifies the path to the program-data folder (normally C:\ProgramData). Unlike the Program Files folder, this folder can be used by applications to store data for standard users, because it does not require elevated permissions.


2 Answers

I think CommonApplicationData is exactly what you're looking for, as it's the global folder for all applications which are not bound to a user.

var commonpath = GetFolderPath(SpecialFolder.CommonApplicationData);
var path = Path.Combine(commonpath, "YourAppName\\YourApp.exe");
try { 
    Process.Start(path);
    // or put data there or whatever
} 
catch (Exception ex)
{
    MessageBox.Show(path);
}

There's also SpecialFolder.LocalApplicationData for user-bound data.

like image 53
Akku Avatar answered Sep 19 '22 22:09

Akku


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 <User folder>\AppData\Roaming\..., or <User folder>\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.

like image 23
superjos Avatar answered Sep 18 '22 22:09

superjos