我的 winform 应用程序使用 xml 文件来存储数据,我应该将它们存储在哪里,以便 Vista 用户可以写入它们? [英] My winform app uses xml files to store data, where should I store them so Vista users can write to them?

查看:22
本文介绍了我的 winform 应用程序使用 xml 文件来存储数据,我应该将它们存储在哪里,以便 Vista 用户可以写入它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 winform 应用程序使用 xml 文件来存储数据,我应该将它们存储在哪里以便 Vista 用户可以写入它们?

My winform app uses xml files to store data, where should I store them so Vista users can write to them?

谢谢

推荐答案

使用 Environment.GetFolderPath 以独立于操作系统的方式获取最合适的文件夹.

Use the Environment.GetFolderPath to get the most appropriate folder in an OS-independent manner.

特别是,您需要以下特殊文件夹值之一:

In particular, you need one of the following SpecialFolder values:

  • ApplicationData - 如果文件是漫游的,每个用户,并且仅供应用程序使用,不代表用户可能关心的文档.
  • LocalApplicationData - 如果文件是非漫游的、每个用户且仅供应用程序使用且不代表用户可能关心的文档.
  • CommonApplicationData - 如果文件是漫游的,对所有用户都是通用的,并且仅供应用程序使用,不代表用户可能关心的文档.注意:在 Vista 上,它映射到 C:\ProgramData,默认情况下,它对普通用户是只读的(因为更改那里的文件可能会影响管理员使用的程序的行为).您可以明确更改应用子文件夹的权限,也可以选择其他选项之一.
  • MyDocuments - 如果文件是针对每个用户的并且代表文档.
  • ApplicationData - if the files are roaming, per-user and are for the application use only and don't represent documents the user might care about.
  • LocalApplicationData - if the files are non-roaming, per-user and are for the application use only and don't represent documents the user might care about.
  • CommonApplicationData - if the files are roaming, common for all user and are for the application use only and don't represent documents the user might care about. NOTE: On Vista this maps to C:\ProgramData, which is by default read-only for regular users (due to the fact that changing files in there might affect behavior of programs used by admins). You can either explicitly change the permissions on your app subfolder, or choose one of the other options.
  • MyDocuments - if the files are per-user and represent documents.

请注意,没有像 CommonDocuments 这样的 SpecialFolder 枚举值代表机器范围的文档存储,即使有一个文件夹用于像一个 (C:\Documents and Settings\All Users\Documents 在 XP 和 C:\Users\Public\Documents 在 Vista 上).如果您想写入这些位置,您必须自己找到操作系统版本并选择适当的文件夹.

Note that there's no SpecialFolder enum value like CommonDocuments that would represent machine-wide document store, even though there is a folder intended to serve like one (C:\Documents and Settings\All Users\Documents on XP and C:\Users\Public\Documents on Vista). You will have to find the OS version yourself and choose the appropriate folder if you want to write to these locations.

在内部 Environment.GetFolderPath 使用 Win32 API SHGetFolderPath.SHGetFolderPath 使用的枚举为您提供了几个其他特殊文件夹(包括公共文档)的众所周知的位置.你可以直接使用 SHGetFolderPath;您可以找到它的 p/invoke 定义 和相应的 CSIDL 枚举定义在 PInvoke.net 上.

Internally Environment.GetFolderPath uses the Win32 API SHGetFolderPath. The enumeration used by SHGetFolderPath gives you the well-known locations for several other special folders (including Common Documents). You might use directly SHGetFolderPath; you can find it's p/invoke definition and the corresponding CSIDL enum definition on PInvoke.net.

您还可以使用 IsolatedStorage.但是,它是不可漫游的、每个用户的、配额有限且用户无法从 Windows 资源管理器轻松访问.因此,它实际上相当于 SpecialFolder.ApplicationData 的中等/低信任度.

You can also use the IsolatedStorage. However, it is non-roamable, per-user, with limited quota and is not easily accessible to the user from Windows Explorer. As such, it is really a medium/low-trust equivalent to SpecialFolder.ApplicationData.

这篇关于我的 winform 应用程序使用 xml 文件来存储数据,我应该将它们存储在哪里,以便 Vista 用户可以写入它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆