问题
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