【发布时间】:2016-04-13 17:53:30
【问题描述】:
我收到一个错误
{"访问路径 'C:\storing_PAC_history_10_4_2016.xml' 是 拒绝。”}
当我执行以下代码 db.save(path) 的指令时,它会修改位于 ASP.Net 项目中给定路径的文件。
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);
`
【问题讨论】:
-
将文件存储在 C: 驱动器的根目录不是一个好主意。 ASP.NET 应用程序所在目录的子目录会更好。如有必要,您可以将 IIS 设置为不提供该目录中的文件。