2016-08-04 89 views
1

我在YouTube下載工作的非法字符,我用Path.combine,但是當我啓動我的程序,並把一個網址在現場我得到這個錯誤:影片下載:路徑

illegal characters in path

progressBar.Minimum = 0; 
     progressBar.Maximum = 100; 
     if (!(txturl.Text == string.Empty)) 
     { 
      try 
      { 
       IEnumerable<VideoInfo> videos = DownloadUrlResolver.GetDownloadUrls(txturl.Text); 
       VideoInfo video = videos.First(p => p.VideoType == VideoType.Mp4 && p.Resolution == Convert.ToInt32(cmbResolution.Text)); 
       if (video.RequiresDecryption) 
        DownloadUrlResolver.DecryptDownloadUrl(video); 
       VideoDownloader downloader = new VideoDownloader(video, Path.Combine(Application.StartupPath, video.Title + video.VideoExtension)); 
       downloader.DownloadProgressChanged += downloader_DownloadProgressChanged; 
       Thread thread = new Thread(() => { downloader.Execute(); }) { IsBackground = true }; 
       thread.Start(); 
      } 
      catch (Exception yt) { MessageBox.Show(yt.Message); } 
     } 
     else { MessageBox.Show("Input field cannot be empty."); } 

回答

0

你不需要添加"\\",因爲Path.Combine()會爲您添加它們。

編輯:

例子:Path.Combine(Application.StartupPath, "hello");回報像C:\path\to\exe\hello\

+0

感謝,但仍拒絕工作。請不要使用「目錄GetCurrentDirectory」之類的內容,請不要介意我的錯誤。 –

+0

試試這個:'Path.Combine(Application.StartupPath,string.Format(「{0}。{1}」,video.Title,video.VideoExtension));' –

+0

我已經複製了整個代碼,請幫助我審查並調試它。謝謝sir –