文件权限(写入)

本文关键字:写入 权限 文件 | 更新日期: 2023-09-27 18:10:43

你好,
一旦我得到了这个代码来处理任何错误,它就下载了这个文件
现在它给了我一个权限错误,
我没有弹出窗口应该显示的访问控制
无论如何,
如何获取此代码来下载我的文件

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*/);

由于您编写了/**/,您的"file"变量被注释,这使我假设downloadTo than必须包含包括文件名在内的完整路径。

你能试着硬编码你的目标文件吗?

(例如FileStream f=File.Create(@"c:''''users''您的用户''''myfile.bin"(;

就我所能解释的代码而言,您正试图在不指定文件名的情况下写入Folder。