Nithesh Narayanan
Nithesh Narayanan

Reputation: 11765

'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 that '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.

Upvotes: 1

Views: 4524

Answers (3)

Yahia
Yahia

Reputation: 70369

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.

Upvotes: 2

Brandon Moore
Brandon Moore

Reputation: 8780

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

Upvotes: 1

Pankaj Upadhyay
Pankaj Upadhyay

Reputation: 13584

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

Upvotes: 1

Related Questions