URI Formats not Supported: while downloading remote file from Web client in c#

拈花ヽ惹草 提交于 2020-01-07 03:22:11

问题


I'm trying to download a file from the server . While passing a link to the download File , it is throwing an error

**URI Formats are not supported ** and pointing at "link "- string contains server file address

string link =
    http:\\www.nse-india.com\DERIVATIVES\2012\AUG\fo22AUG2012bhav.csv.zip

          WebClient wc = new WebClient();

        var ua = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
        wc.Headers.Add(HttpRequestHeader.UserAgent, ua);
        wc.Headers["Accept"] = "/";

and downloading code goes like this

    try
  {
   wc.DownloadFile(@link, "H:\\ZipTest\\ZipText\\nt.zip"); // Here Showing error
  _status = true;
   fileCount++;

  } catch (Exception ex)

  {
    MessageBox.Show(ex.Message);
    _status = false;
    }

if i used the same address in the web browser it downloading properly or if a replace some other files then also i can download from the same code only for this particular file i am facing problem , any idea??


回答1:


Url need little modification

Change

string link =
    "http:\www.nse-india.com\DERIVATIVES\2012\AUG\fo22AUG2012bhav.csv.zip"

To

string link =
    "http://www.nse-india.com/DERIVATIVES/2012/AUG/fo22AUG2012bhav.csv.zip"



回答2:


Your url is corrupted: http:\www.nse-indi........ It should be something like http://www.nse-india.com/DERIVATIVES/2012/AUG/fo22AUG2012bhav.csv.zip



来源:https://stackoverflow.com/questions/12323269/uri-formats-not-supported-while-downloading-remote-file-from-web-client-in-c-sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!