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

前端 未结 2 618
隐瞒了意图╮
隐瞒了意图╮ 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:44

    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.

提交回复
热议问题