1

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.

Nithesh Narayanan
  • 11,481
  • 34
  • 98
  • 138

3 Answers3

2

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.

Yahia
  • 69,653
  • 9
  • 115
  • 144
1

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

Pankaj Upadhyay
  • 12,966
  • 24
  • 73
  • 104
  • Don't a lot of programs have config/setting files inside the Program Files folder that can be modified within the program? – Jack Nov 16 '11 at 05:30
  • Well those applications start under admin rights and that why they are able to do these stuff. He can do that by forcing his application to start under admin priveleges by embedding custom manifest (project properties -> build -> Manifest) – Pankaj Upadhyay Nov 16 '11 at 05:36
  • @Jack in the past perhaps - but since Vista security has been tightened more and more and esp. write access inside program folders is restricted... – Yahia Nov 16 '11 at 05:36
1

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

Brandon Moore
  • 8,590
  • 15
  • 65
  • 120
  • If this is an applicable solution for you then it will keep you from having to tell people that they have to run your app as administrator. – Brandon Moore Nov 16 '11 at 05:52