2012-03-27 5 views
4

Windows APP가있는 상황입니다. DownloadFile이 "경로의 일부를 찾을 수 없습니다"예외를 발생시키는 곳을 개발 중입니다."경로의 일부를 찾을 수 없습니다"DownloadFile

방법 내 하드 드라이브에 원격 zip 파일을 저장하기 위해 사용하고는 다음과 같습니다

private void f_begin_download(string remoteURL) 
    { 
     string directoryName = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); 
     //MessageBox.Show(directoryName); 

     filePath = directoryName + "\\tmp\\"; 
     filePath = f_make_directory(filePath); 

     Uri remoteURI = new Uri(remoteURL); 
     System.Net.WebClient downloader = new System.Net.WebClient(); 

     downloader.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(f_downloader_DownloadFileCompleted); 
     try 
     { 
      downloader.DownloadFile(remoteURI, filePath); 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(remoteURI.ToString()); 
      MessageBox.Show(filePath); 
      MessageBox.Show(ex.ToString()); 
     } 
    } 

이 방법은 실제로 내 응용 프로그램 디렉토리에있는/tmp를/폴더를 만듭니다.

public static string f_make_directory(string path) 
    { 
     try 
     { 
      System.IO.DirectoryInfo newFolder = new System.IO.DirectoryInfo(path); 
      if (!newFolder.Exists) 
      { 
       newFolder.Create(); 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.ToString()); 
     } 
     return path; 
    } 

을하지만이 과정을 실행할 때 예외는 다음과 같습니다 : 그것은 성공적으로 너무 폴더를 만들 않습니다 C에서 WindowsFormsApplication1.window_updater.f_begin_download (문자열 remoteURL)에서

System.Net.WebException: An exception occurred during a WebClient request. -->  System.IO.DirectoryNotFoundException: Could not find a part of the path' C:\Users\Hudson Atwell\Desktop\The Big Test Folder\tmp\'. 
at System.IO.__Error.WinIOError(Int32 errorCode,String maybeFullPath) 
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRight, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msyPath, Boolean bFromProxy, Boolean useLongPath) 
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at System.Net.WebClient.DownloadFile(Uri address, String fileName) 

: \ 사용자 \ Hudson Atwell \ Documents \ Visual Studio \ Projects \ Test 프로젝트 \ 테스트 프로젝트] Windows \ window_update.cs : line 125

솔루션을 관리자로도 실행해야합니다.

내가 잘못하고있는 것에 대한 조언이 있으십니까?

답변

8

메서드에서 파일 이름을 필요로하는 동안 디렉토리 이름을 전달합니다. 그 이름을 가진 디렉토리가 이미 있기 때문에 그 이름을 가진 파일을 생성하려는 시도는 실패합니다.

+0

하하는 내가 그것을 보지 못했다고 믿을 수 없다. - 그리고 10k를 축하해 .-) – BrokenGlass

+0

네 말이 맞아, 지금은 효과가있다. 다운로드 한 파일 이름 뒤에 자동 이름을 붙일 것이라고 생각했습니다. 고맙습니다! – atwellpub

+0

이 답변으로 문제가 해결되면 커뮤니티의 이익을위한 답으로 받아 들여야합니다. –

관련 문제