我有一个 C# 应用程序,我将一些数据写入文件。我在 Windows 7 专业版上遇到的问题是,当我将数据写入 时C:\ProgramData
,会抛出 Access denied 接受。如果我从管理员帐户登录,此问题就会消失,如果我从其他具有管理权限的帐户登录,则会出现此问题。此问题仅在 windows 7 专业版上产生,它在所有其他版本的 windows 7 以及 windows vista 上运行良好。
try
{
XmlTextWriter myXmlTextWriter = new XmlTextWriter("Configuration.xml", null);
myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument(true);
myXmlTextWriter.WriteDocType("ApplicationConfigurations", null, null, null);
////myXmlTextWriter.WriteComment("This file represents another fragment of a book store inventory database");
myXmlTextWriter.WriteStartElement("Configuration");
myXmlTextWriter.WriteElementString("firstElement", pe.ToString());
myXmlTextWriter.WriteEndElement();
myXmlTextWriter.WriteEndDocument();
myXmlTextWriter.Flush();
myXmlTextWriter.Close();
}catch(Exception e)
{
//Exception is thrown in Win7 professional
}