Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File Access denied in .NET

Tags:

c#

I am writing an application in c# which saves data to xml. When i reopen the application it says

Access to the path 'C:\ProgramData\Test\abc.xml' is denied.

Can any one pls help me to sort out this problem.

Is there any way to find why access is denied.

like image 924
Timmi Avatar asked Jan 24 '23 09:01

Timmi


1 Answers

You're probably getting this error because you're running Vista or Win7 and you have UAC turned on.

C:\ProgramData requires admin priveledges to write to (but not read from).

I just found this out the hard way because I've been working on a program that was working fine on XP that used System.Environment.SpecialFolder.CommonApplicationData which in Vista refers to the above location and requires elevated privs to write to that directory.

like image 103
Joseph Avatar answered Jan 25 '23 23:01

Joseph