C# “SpecialFolder.LocalApplicationData”和“SpecialFolder.ApplicationData”之间的区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9709269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 08:30:31  来源:igfitidea点击:

Difference between 'SpecialFolder.LocalApplicationData' and 'SpecialFolder.ApplicationData'?

c#.netwindowsapplication-settingsappdata

提问by Tarion

On my system, %AppData%leads to ApplicationDatawhich is C:\Users\<USER>\AppData\Roaming

在我的系统上,%AppData%导致ApplicationData哪个是C:\Users\<USER>\AppData\Roaming

But there is also C:\Users\<USER>\AppData\Local
And for some more confusion D:\Users\<USER>\AppData\LocalLow

但也有C:\Users\<USER>\AppData\Local
一些更多的困惑D:\Users\<USER>\AppData\LocalLow

string local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string roaming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

My question is, to which of these locations should my application save its data?

我的问题是,我的应用程序应该将其数据保存到这些位置中的哪个位置?

Are there guidelines for which of these locations to use? And am I leaving myself open to problems if I choose the wrong location?

是否有使用这些位置的指南?如果我选择了错误的位置,我是否会让自己面临问题?

采纳答案by Roger Lipscombe

The Roamingfolder is copied between machines when roaming profiles are enabled (in a domain environment). Use it for application data that you want to share between machines. But don't store large files in there -- IT departments don't like it when you do that, and it increases the time taken for the user to log in and to log out as the files are copied around.

Roaming当启用漫游配置文件(在域环境中)时,将在计算机之间复制该文件夹。将它用于要在机器之间共享的应用程序数据。但是不要在那里存储大文件——当你这样做时,IT 部门不喜欢它,并且随着文件的复制,它增加了用户登录和注销所需的时间。

The Localfolder is not copied between machines. Use it for application data that's specific to a machine.

Local文件夹不会在机器之间复制。将其用于特定于机器的应用程序数据。

The LocalLowfolder is used for low-privilege tasks (such as Internet Explorer). You shouldn't need to worry about it.

LocalLow文件夹用于低权限任务(例如 Internet Explorer)。你不应该担心它。

For files that the user specifically saved, you should put them (by default) in the Documentsfolder.

对于用户专门保存的文件,您应该将它们(默认情况下)放在Documents文件夹中。

回答by Yahia

According to MSDNthe difference is that LocalApplicationDatastays on the local machine and does not roam... ApplicationDatadoes roam for example if the user logs onto the domain from a different computer it will be synced...

根据MSDN,不同之处在于它LocalApplicationData停留在本地机器上并且不漫游......ApplicationData例如,如果用户从不同的计算机登录到域,它将被同步......

The LocalLowrefers to specific situations likea BHO running in "Protected Mode" of IE...

LocalLow指likea BHO运行的具体情况,在IE的“保护模式” ...

For a standard application always use ApplicationData. Use LocalApplicationDatafor things that should NOT roam with the user...

对于标准应用程序,始终使用ApplicationData. 使用LocalApplicationData的东西,不应该与用户漫游...

回答by Oded

From MSDN - Environment.SpecialFolder Enumeration:

从 MSDN - Environment.SpecialFolder 枚举

ApplicationData - The directory that serves as a common repository for application-specific data for the current roaming user. A roaming user works on more than one computer on a network. A roaming user's profile is kept on a server on the network and is loaded onto a system when the user logs on.

LocalApplicationData The directory that serves as a common repository for application-specific data that is used by the current, non-roaming user.

ApplicationData - 作为当前漫游用户特定于应用程序数据的公共存储库的目录。漫游用户在网络上的多台计算机上工作。漫游用户的配置文件保存在网络上的服务器上,并在用户登录时加载到系统上。

LocalApplicationData 用作当前非漫游用户使用的特定于应用程序的数据的公共存储库的目录。

In short, use ApplicationDatafor roaming profiles, and LocalApplicationDatafor non roaming profiles.

简而言之,ApplicationData用于漫游配置文件和LocalApplicationData非漫游配置文件。