2012-03-27 12 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) 

:\ Users \ユーザーHudson Atwell \ Documents \ Visual Studio \ Projects \ Testプロジェクト\テストプロジェクト] Windows \ window_update.cs:line 125

私は解決策を管理者として実行する必要があります。

私が間違っていることについてのアドバイスはありますか?

答えて

8

ファイル名が必要なディレクトリ名を渡しています。その名前のディレクトリがすでに存在するため、その名前のファイルを作成しようとすると失敗します。

+0

私はそれを見ていないと信じられません。そして、10kでお祝いしてください;-) – BrokenGlass

+0

あなたはそうです、それは今働きます。ダウンロードしたzipのファイル名の後に自動的に名前を付けると思った。ありがとうございました! – atwellpub

+0

この回答があなたの問題を解決した場合は、それをコミュニティの利益のための答えとして受け入れるべきです。 –

関連する問題