2011-10-09 33 views
0

你好,
一旦我得到这个代码来处理任何erros,并下载文件。
现在它给了我一个权限错误,
我没有得到该窗口应该显示的acesscontrol弹出窗口。
反正,
我怎样才能得到这段代码来下载我的文件?
文件许可(写)

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/*[email protected]"\"+file*/); 
    f.Write(fileData, 0, fileData.Length); 
    f.Close(); 
    MessageBox.Show("Completed!"); 
} 
catch(Exception e) 
{ 
    MessageBox.Show(e.Message); 
} 
+0

尝试以管理员身份运行您的应用程序 – 2011-10-09 12:28:24

+0

WinForms或ASP.NET? –

+0

它仍然给我同样的错误...“访问拒绝路径...被拒绝。 “(&for @ShadowWizard,WinForms) – funerr

回答

1

什么是'downloadTo'变量?我有点困惑你的代码。既然你可以执行GetAccessControl()我假设它必须包含你的文件夹。如果它是你的文件,它会失败,因为它还不存在。

,但你的代码继续

FileStream f = File.Create(downloadTo/*[email protected]"\"+file*/); 

,因为你写的/ * * /你的“文件”变量评价说,这让我承担downloadTo比必须包含完整路径,包括文件名。

你可以尝试和硬编码您的目标文件?

(如的FileStream F = File.Create(@ “C:\\ \\用户的用户 \\ myfile.bin”);

至于我能理解你的代码,你想在没有指定文件名的情况下写入文件夹

+0

谢谢,但我想到了(这是我所做的)。 – funerr