[英]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.