2017-09-05 80 views
0

我有位於http://10.1.10.211:8600/CardsPro+.exe檢索文件從IIS服務器將使用特殊字符名稱C#.NET

一個文件,我想用下面的代碼檢索它,但得到的錯誤 「HTTP錯誤404.11 - 未找到

private WebClient webClient; 
    private BackgroundWorker bgWorker; 
    private string tempFile; 
    private string md5; 
    internal string TempFilePath 
    { 
     get { return this.tempFile; } 
    } 
    internal UpdateInfoDownloadForm(Uri location, string md5, Icon programIcon) 
    { 
     InitializeComponent(); 
     if (programIcon != null) 
     { 
      this.Icon = programIcon; 
     } 
     tempFile = Path.GetTempFileName(); 
     this.md5 = md5; 
     webClient = new WebClient(); 
     webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged); 
     webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted); 

     bgWorker = new BackgroundWorker(); 
     bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork); 
     bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BgWorker_RunWorkerCompleted); 

     try 
     { 
      string strend = location.ToString().Substring(location.ToString().LastIndexOf('/')+1); 

      string strstart = location.ToString().Substring(0,location.ToString().LastIndexOf('/')+1); 

      strend = System.Web.HttpUtility.UrlEncode(strend); 
      Uri locn = new Uri(strstart+strend); 
      webClient.DownloadFileAsync(locn, this.tempFile); **//It fails here** 
     } 
     catch(Exception ex) 
     { this.DialogResult = DialogResult.No; this.Close(); } 
    } 

我如何通過URI來獲得具有特殊字符在它的名稱的文件?

當我更改文件名時它起作用。

回答