我使用以下函数将数据写入用户应用程序文件夹
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
(当前用户,非漫游数据)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)