2011-10-09 38 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