繁体   English   中英

Windows 7 Professional中C#中的文件写入问题

[英]File writing problem on Windows 7 Professional in c#

我在C#中有一个应用程序,可以将一些数据写入文件。 我在Windows 7 Professional上遇到的问题是,当我将数据写入C:\\ProgramData ,将引发访问拒绝接受。 如果我从管理员帐户登录,则此问题消失,如果我从具有管理特权的其他帐户登录,则出现此问题。 此问题仅在Windows 7 Professional上产生,它在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
}

这是正常的,非管理员用户帐户没有对c:\\ programdata的写权限。 默认情况下,仅分配“读取”,“执行”和“列表”权限。 这包括启用了UAC的管理员帐户。

AppData文件夹应用于写入文件。 使用Environment.GetFolderPath()获取该文件夹的路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM