c# – 将文件写入Common Application Data文件夹被拒绝
发布时间:2020-12-15 18:17:54 所属栏目:百科 来源:网络整理
导读:我使用了follwing函数将数据写入用户应用程序文件夹 private void WriteToLog(string source,string method,string msg){ string LogFile =Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "test"; LogFile = LogFile + "
我使用了follwing函数将数据写入用户应用程序文件夹
private void WriteToLog(string source,string method,string msg) { string LogFile =Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "test"; LogFile = LogFile + "Log.txt"; StreamWriter sw = new StreamWriter(LogFile,true ); string str = DateTime.Now.ToString() + "source=" + source + "t Method=" + method + "t" + msg; sw.WriteLine(str); sw.Flush(); sw.Close(); } 上述代码在管理员帐户中完美运行,但在有限的用户帐户中失败 解决方法
受限用户通常不具有对所有用户共有的文件夹的写访问权.你确定你不是要写一个不同的文件夹吗?
例如,您可以使用Environment.SpecialFolder.ApplicationData(当前用户,漫游数据)或Environment.SpecialFolder.LocalApplicationData(当前用户,非漫游数据). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |