如何获取应用程序特定的数据文件夹(ProgramData)? [英] 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.
我尝试使用 Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData)
,但它只返回 C:\ProgramData 。
I tried to use Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
, but it returns only C:\ProgramData.
我的问题是:
是否存在像 Path.GetDirectoryName(Application.UserAppDataPath)
这样的系统,
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?
还是 ProgramData 不是正确的位置?
谢谢。
推荐答案
我认为CommonApplicationData正是您想要的东西,因为
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);
}
还有用于用户绑定数据的SpecialFolder.LocalApplicationData。
There's also SpecialFolder.LocalApplicationData for user-bound data.
这篇关于如何获取应用程序特定的数据文件夹(ProgramData)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!