Reputation: 309
I get an error
{"Access to the path 'C:\storing_PAC_history_10_4_2016.xml' is denied."}
when I execute the instruction of the following code db.save(path)
which modify the file located at the given path in an ASP.Net project.
XDocument doc = XDocument.Load(path);
XElement root = new XElement("Command");
root.Add(new XElement("StartDateTime", _commandsLog.StartDateTime.ToString()));
root.Add(new XElement("CommandName", _commandsLog.CommandName));
root.Add(new XElement("Output", _commandsLog.Output));
root.Add(new XElement("UserOutput", _commandsLog.UserOutput));
root.Add(new XElement("Status", _commandsLog.Status.ToString()));
root.Add(new XElement("EndDateTime", _commandsLog.EndDateTime.ToString()));
root.Add(new XElement("UserName", _commandsLog.UserName));
doc.Element("CommandsLogs").Add(root);
doc.Save(path);
`
Upvotes: 0
Views: 5179
Reputation: 76607
If you are debugging your application locally, you might ensure that you are running Visual Studio with Administrative Rights (i.e. Right-click > Run as Administrator
) as the process spawned from it will likely not be able to access directories that would otherwise require it.
Otherwise, you can check the permissions on one of the following roles, which will vary depending on which version of IIS you are using and ensure that it has the proper permission(s) :
IIS_IUSRS
IIS APPPOOL\DefaultAppPool
NETWORK_SERVICE
As mentioned by others, it's not a good idea to give root access to your applications. If you are going to be using this in any kind of production manner (outside of a quick and dirty utility application running on your local machine), you should consider using a sub-directory from within your application and referencing the files from there (i.e. drop the files you are attempting to access in your Project and access them relative to your application).
Upvotes: 1