C# 文件权限(写入)
你好,C# 文件权限(写入),c#,winforms,webclient,permission-denied,C#,Winforms,Webclient,Permission Denied,你好, 一旦我得到了这段代码来解决任何错误,它就下载了文件。 现在它给了我一个权限错误, 我没有看到窗口应该显示的AcesControl弹出窗口。 无论如何, 如何获取此代码以下载我的文件? WebClient request = new WebClient(); request.Credentials = new NetworkCredential(txtFTPuser.Text, txtFTPpassword.Text); byte[] fileData = request.Download
一旦我得到了这段代码来解决任何错误,它就下载了文件。
现在它给了我一个权限错误,
我没有看到窗口应该显示的AcesControl弹出窗口。
无论如何,
如何获取此代码以下载我的文件?
WebClient request = new WebClient();
request.Credentials = new NetworkCredential(txtFTPuser.Text, txtFTPpassword.Text);
byte[] fileData = request.DownloadData(fullDownloaPath);//dnoces.dreamhost.com
FileSecurity security = File.GetAccessControl(downloadTo);
FileSystemAccessRule rule = new FileSystemAccessRule(@"BUILTIN\Users",
FileSystemRights.FullControl, AccessControlType.Allow);
File.SetAccessControl(downloadTo, security);
try
{
FileStream f = File.Create(downloadTo/*+@"\"+file*/);
f.Write(fileData, 0, fileData.Length);
f.Close();
MessageBox.Show("Completed!");
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
“downloadTo”变量中有什么?我对你的代码有点困惑。因为您可以执行GetAccessControl(),所以我假定它必须包含您的文件夹。如果它是您的文件,它将失败,因为它还不存在 但是,您的代码继续使用
FileStream f = File.Create(downloadTo/*+@"\"+file*/);
由于您编写了/**/your'file'变量,因此我假设downloadTo必须包含包含文件名的完整路径
你能尝试硬编码你的目标文件吗
(例如FileStream f=File.Create(@“c:\\users\\your user\\myfile.bin”)
就我所能理解的而言,您试图在不指定文件名的情况下写入文件夹的代码。尝试以管理员身份运行应用程序,但仍然会出现相同的错误…”“拒绝访问路径…”(对于@ShadowWizard,WinForms)给出错误的确切行是什么?更改为
MessageBox.Show(例如ToString())
查看堆栈跟踪的完整错误。-错误游戏文件夹是一个虚拟shell文件夹。选择一个真实的目录。谢谢,但我已经计算出来了。(这就是我所做的)。