Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal characters in path with web.downloadstring

Tags:

c#

webforms

I'm trying to use regex to retrieve names from a website. However I get the error using "Illegal characters in path" when I run the program. Here's the code:

private void button1_Click(object sender, EventArgs e)
{
    List<string> givenNames = new List<string>();

    WebClient web = new WebClient();

    for (int i = 10000; i <= 33852; i++)
    {   
        string numberurl = i.ToString();
        string mainurl = "www.cpso.on.ca/docsearch/details.aspx?view=1&id=+" + numberurl;
        String html = web.DownloadString(mainurl);

        Match m = Regex.Match(html, @"</strong>\s*(.+?)\s*&nbsp;", RegexOptions.Singleline);

        string givenName = m.Groups[1].Value;
        givenNames.Add(givenName);
    }
    listBox1.DataSource = givenNames; 
}

The error occurs at String html = web.DownloadString(mainurl);. I tried using HttpUtility.UrlEncode but it still did not work. I appreciate the help.

like image 330
J-Y Avatar asked Aug 03 '12 17:08

J-Y


1 Answers

you need to include http:// in the URL.

string mainurl = "http://www.cpso.on.ca/docsearch/details.aspx?view=1&id=+" + numberurl;
like image 136
Misha Avatar answered Oct 20 '22 00:10

Misha