2011-10-09 4 views
0

안녕하세요,
일단이 오류가 발생하지 않도록이 코드를 다운로드하고 파일을 다운로드했습니다.
이제 권한 오류가 발생합니다.
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

응용 프로그램을 관리자로 실행하십시오. –

+0

WinForms 또는 ASP.NET? –

+0

여전히 내게 동일한 오류가 발생합니다 ... "경로에 대한 액세스가 거부되었습니다. ... 거부되었습니다. "(& ShadowWizard, WinForms의 경우) – funerr

답변

1

'downloadTo'변수에는 무엇이 있습니까? 나는 당신의 코드에 약간 혼란 스럽다. GetAccessControl()을 수행 할 수 있으므로 폴더가 있어야한다고 가정합니다. 그것이 당신의 파일 일 경우 아직 존재하지 않기 때문에 실패 할 것입니다. 당신은/* */당신의 '파일'변수가 파일 이름을 포함한 전체 경로를 포함해야합니다보다 나를 downloadTo을 생각하게하는, 주석 쓴 이후

하지만 다음 코드는

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

를 계속합니다.

대상 파일을 하드 코드 할 수 있습니까?

(예 : 파일 스트림 F = File.Create (@ "C : \\ 사용자 \\ 사용자 \\ myfile.bin에");

지금까지 내가 당신이하려는 코드를 해석 할 수 파일 이름을 지정하지 않고 폴더에 쓸 수 있습니다.

+0

고마워요.하지만 생각했습니다. (이것이 내가 한 것입니다.) – funerr