无法修改“所有用户”下的文件使用C#编程在windows 7中的文件夹
这是我的场景,
我有一个 Outlook 加载项,我通过该加载项将一些信息写入一个通用文件中。当我创建可安装文件时,我将通用文件保存在“所有用户”(通用应用程序数据文件夹)文件夹下。当我在 XP 上安装此插件时,它工作得很好,没有权限问题。
现在,当我将此应用程序移至 Windows 7 时,我收到一些文件访问权限异常。参考一些博客,我在“所有用户”下添加了应用程序特定文件夹。此后我也无法写入该文件。
我还需要做什么才能写入此文件。
我读过一些关于UAC的博客,但是,我没有清楚地了解它在外接程序中的用途。
Here is my scenario,
I have an Outlook add-in which, I am writing some information into a common file through this Add-In. When I created a installable, I kept common file under "All Users"(Common Application Data Folder) folder. When I install this add-in on XP it is working perfectly fine and no issue of permission.
Now, when i move this application to Windows 7, I am getting some file access permission exception. With reference to some blogs, I have added application specific folder under "All Users." After this also I am unable to write into this file.
Is there anything else that I need to do, by which I will able to write into this file.
I have read some blogs about UAC, however, I didn't get clear picture of its use for Add-in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,标准用户没有对通用应用程序数据文件夹的写入权限。如果您希望允许用户在那里写入,您应该创建一个子文件夹并应用适当的 ACL。请在安装过程中执行此操作,因为此时您有足够的权限来创建 ACL。
另一种选择是基于每个用户存储这些设置,从而避免安全问题。
By default, standard users don't have write access to the common app data folder. If you wish to allow your users to write there you should create a sub-folder and apply an appropriate ACL. Do this as part of your installation because that's when you have sufficient rights to create the ACL.
Another option is to store these settings on a per-user basis and thereby avoid the issues with security.
要向文件添加特定权限,我使用为此创建的辅助扩展函数:(您需要正确的权限才能在文件上执行此操作)
您可以这样调用它:
您必须添加引用
System.ServiceModel< /code> 到您的项目。您还必须在文件创建之后调用它,在此之前调用它没有任何好处。
To add specific permissions to files, I use a helper extension function I created for this: (You need the right privs to do this on a file)
You call it like this:
You have to add the reference
System.ServiceModel
to your project. You must also call it after the file has been created, it doesn't do any good to call it before then.