创建 XML 文件,并为所有 Windows 帐户用户授予写入权限
我正在使用 C# 在通用应用程序文件夹中创建一个 XML 文件:
%ALLUSERSPROFILE%\Application Data\
安装应用程序时将创建文件。这个文件是本地计算机的所有用户所共有的。(即它包含一些设置信息)
但我的问题是当该文件由管理员用户创建时(即应用程序由管理员用户安装)其他用户没有该文件的写权限。当我检查文件的属性时,它只向其他用户提供了“读取和执行”。
我正在使用下面的代码来保存文件
XDocument.Save(filePath);
是否可以创建向所有用户授予写访问权限的文件?非常感谢任何帮助!
I am creating an XML file in the common application folder using C#:
%ALLUSERSPROFILE%\Application Data\
File will be created when application is installed. This file is something that is common to all the users of the local machine.(i.e it contains some setting information)
But my problem is when the file is created by an admin user(i.e application is installed by an admin user) the other users don't have write access to the file. When I checked the attributes of the file, it has given only 'read and execute' is given to other users.
I am using below code to save the file
XDocument.Save(filePath);
Is it possible to create file with write access given to all users? Any help much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法将有关 ACL 的信息传递到 XDocument.Save 方法中,但您可以在保存 xml 文档后修改文件的权限。您可以使用以下代码来执行它(不要忘记添加对 System.Security.dll 的引用):
You can't pass information about ACL into XDocument.Save method, but you can modify permissions of file after saving your xml document. You can use the following code to perform it (don't forget to add reference to System.Security.dll):
我认为您无法将参数传递给 XDocument.Save 来控制权限,但您应该能够在保存后设置它们。应该执行类似以下操作:
I don't think you can pass a parameter to XDocument.Save to control the permissions but you should be able to set them after the save. Something like the following should do:
我在服务安装时遇到了类似的问题。您可以使用以下代码为文件夹授予不同的权限。
I had a similar problem with a service install. You can use the following code to give a folder different permissions.