简体   繁体   中英

'Access denied' to an xml file in windows application

In my .net windows application am using a xml file . But after installing the application by creating setup, while I am running tha t 'Access Denied' to that xml file message is shown.

I am using System.IO.File methods for doing file operations.

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!

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 ). 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. I would suggest you to save your xml file in * 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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