【发布时间】:2013-06-08 15:51:49
【问题描述】:
您好,我想创建一个程序,将文件保存到我的文档\test。 该文件是.exe。由于某种未知原因,我收到拒绝访问错误,当我测试程序试图保存 .txt 文件(使用 StreamWriter)时,程序运行没有任何问题。 请各位大侠帮帮我。
以下代码抛出错误
byte[] myfile = Properties.Resources.WallPaper;
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string path2 = path + @"\" + "test";
System.IO.Directory.CreateDirectory(path2);
File.WriteAllBytes(path2, myfile);
以下代码在保存 .txt 文件时可以正常工作
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string path2 = path + @"\" + "test";
System.IO.Directory.CreateDirectory(path2);
StreamWriter file = new StreamWriter(path2 + @"\" + "text.txt");
【问题讨论】:
-
您能否发布您遇到的异常,以便我们获得更好的图片
-
unauthorizedAccessExepetion - 访问路径“C:\Users\michael\Documents\test”被拒绝
标签: c# byte access-denied