Take the 2-minute tour ×

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.

share|improve this question
where does the xml file reside ? in the application directory ? –  Yahia Nov 16 '11 at 4:57
Tried running your program elevated? If that solves the problem you should store your file somewhere besides Program Files, where you have non-elevated write access. (e.g. the user's profile). See this question: stackoverflow.com/questions/2362946/… –  Merlyn Morgan-Graham Nov 16 '11 at 5:02
@Yahia: Yes. Inside application directory there is a folder named XMl inside that words.xml –  Nithesh Nov 16 '11 at 5:09
How are you giving the path is it relative path ? Can you post the relevant code ? –  V4Vendetta Nov 16 '11 at 5:28
Application.StartupPath+"\\xml\\words.xml". Like this. –  Nithesh Nov 16 '11 at 5:29

3 Answers 3

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.

share|improve this answer

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

share|improve this answer
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 5: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 5: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 5:36

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:


share|improve this answer
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 5:52

Your Answer


