rmmarsh
asked on
Access to path is denied
I have the following line of code; when running on Vista or Win 7, I get the above message. So I figured that I'm not supposed to put application data in the Program Files directory.
So where is it supposed to go?
So where is it supposed to go?
string xmlFilename = System.AppDomain.CurrentDomain.BaseDirectory + "Options.xml";
if (File.Exists(xmlFilename))
{
File.SetAttributes(xmlFilename, FileAttributes.Normal); // so we can write on the file
using (XmlReader tr = XmlReader.Create(xmlFilename))
{
ASKER
Can't right click on the folder because it's on the user's machine.
Also, this is not ASPNET, it's C# .NET...
Also, this is not ASPNET, it's C# .NET...
ASKER
Actually, I changed the path to take it out of the c:\program files directory. Now, I don't get an error on the read, but only on the write. New code is below.
string filename = @"C:\Prager\prager.Options.xml";
XmlTextWriter tw = null;
try
{
tw = new XmlTextWriter(filename, null); //null represents the Encoding Type
}
catch (Exception ex)
{
if (ex.Message.Contains("prager.Options.xml' is denied"))
{
MessageBox.Show("You do not have write permission to the prager.Options.xml file. Disable UAC or run this program as Administrator, otherwise your options will not be saved.", "Prager, Software", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What Carnou said. You need to use the users profile to store program data, as Vista and Windows 7 by default don't allow programs to write to other locations. This has long been a programming rule and guideline from Microsoft for security. In Windows 7 and Vista they are finally enforcing it.
ASKER
Thank you so much... I appreciate it.
Select properties
Select Security Tab
type ASPNet and click OK
Now select ASPNET and set the read and write permissions