简体   繁体   English

'访问被拒绝'到Windows应用程序中的xml文件

[英]'Access denied' to an xml file in windows application

In my .net windows application am using a xml file . 在我的.net windows应用程序中使用的是xml文件。 But after installing the application by creating setup, while I am running tha t 'Access Denied' to that xml file message is shown. 但是after installing the application通过创建安装after installing the application ,当我运行时,显示t 'Access Denied' to that xml文件消息。

I am using System.IO.File methods for doing file operations. 我正在使用System.IO.File方法进行文件操作。

If any body knows the solution pls share. 如果任何机构知道解决方案请分享。

Write access to program directory has been more and more restricted (starting with XP/Vista) since that is a secruity risk! 对程序目录的写访问受到越来越多的限制(从XP / Vista开始),因为这是一个安全风险!

I would suggest to have the "base version" of that file readonly in your program directory... 我建议在你的程序目录中只读取该文件的“基本版本”...

Upon start of your app you check whether it is present in ApplicationData or LocalApplicationData or CommonApplicationData - (to get the real path at runtime use Environment.GetFolderPath ). 在启动应用程序时,检查它是否存在于ApplicationDataLocalApplicationDataCommonApplicationData - (在运行时获取实际路径使用Environment.GetFolderPath )。 If it is not there then copy it there - in those locations your application has write access by default with no need for Administrator rights. 如果不存在,则将其复制到那里 - 在这些位置,您的应用程序默认具有写访问权限,而无需管理员权限。

Program Files folder has limited access and can be modified by Administrator account. Program Files文件夹具有有限的访问权限,可以通过Administrator帐户进行修改。 I would suggest you to save your xml file in * C:\\Users\\YourPCName\\AppData\\Local\\YourAppFolder* . 我建议你将你的xml文件保存在* C:\\ Users \\ YourPCName \\ AppData \\ Local \\ YourAppFolder *中

This way you will be able to access and modify the file 这样您就可以访问和修改文件

I had this problem once so I used Isolated Storage and that fixed my problem. 我有过这个问题所以我使用了隔离存储,这解决了我的问题。 It may or may not work for you depending on the nature of your situation, but here's a quick tutorial on how to use it: 根据您的具体情况,它可能适用于您,也可能不适合您,但这里有一个关于如何使用它的快速教程:

http://www.codeproject.com/KB/dotnet/IsolatedStorage.aspx http://www.codeproject.com/KB/dotnet/IsolatedStorage.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM