title: Problems with HTMLDocument
body: <p>I am new this web crawling world. So Anyone worked on any web application for web crawl ? I need help if someone used asp.net &amp; C# <strong>not</strong> VB.NET windows form.</p>
  
  <p>I have a default webform with 3 text boxes and a button and this is the Code behind:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Net;
  
  using System.IO;
  
  
  
  
  public partial class _Default : System.Web.UI.Page
  {
      String Rstring;
      protected void Page_Load(object sender, EventArgs e)
      {
  
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
          WebRequest myWebRequest;
          WebResponse myWebResponse;
          String URL = TextBox1.Text;
  
          myWebRequest = WebRequest.Create(URL);
          myWebResponse = myWebRequest.GetResponse();//Returns a response from an Internet resource
  
          Stream streamResponse = myWebResponse.GetResponseStream();//return the data stream from the internet
          //and save it in the stream
  
          StreamReader sreader = new StreamReader(streamResponse);//reads the data stream
          Rstring = sreader.ReadToEnd();//reads it to the end
          String Links = GetContent(Rstring);//gets the links only
  
          TextBox2.Text = Rstring;
          TextBox3.Text = Links;
          streamResponse.Close();
          sreader.Close();
          myWebResponse.Close();
  
      }
  
  
      //public ISet&lt;string&gt; GetNewLinks(string content)
      //{
      //    Regex regexLink = new Regex("(?&lt;=&lt;a\\s*?href=(?:'|\"))[^'\"]*?(?=(?:'|\"))");
  
      //    ISet&lt;string&gt; newLinks = new HashSet&lt;string&gt;();
      //    foreach (var match in regexLink.Matches(content))
      //    {
      //        if (!newLinks.Contains(match.ToString()))
      //            newLinks.Add(match.ToString());
      //    }
  
      //    return newLinks;
      //}
  
      private String GetContent(String Rstring)
      {
          String sString = "";
          HTMLDocument d = new HTMLDocument();
          IHTMLDocument2 doc = (IHTMLDocument2)d;
          doc.write(Rstring);
  
          IHTMLElementCollection L = doc.links;
  
          foreach (IHTMLElement links in L)
          {
              sString += links.getAttribute("href", 0);
              sString += "/n";
          }
          return sString;
      }
  }
  </code></pre>