title: WebBrowser Control c#: finding particular link and "clicking" it programmatically?
body: <p>I am working on csv downloader project ,i need to download the CSV files generated on the webpage . and using html agility , i found the exact link that contain the link for csv file </p>
  
  <pre><code>&lt;a href="/content/fo/contractvol/datafiles/OPTIDX_NIFTY_CE_31-08-2012_TO_31-08-2012.csv" target="_blank"&gt;Download file in csv format&lt;/a&gt;
  </code></pre>
  
  <p>now i want , without any activity from my side , the application must detect this link in the web page  ( i could do it by Htmlagility ) and should download the file once the web page fully navigated in Web browser in my app.  I tried some example in one of the SO  <a href="https://stackoverflow.com/questions/3479490/click-an-html-link-inside-a-webbrowser-control">click here</a> post but getting </p>
  
  <blockquote>
    <p>Error :Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <pre><code>HtmlElementCollection links = webBrowser.Document.GetElementsByTagName("A");
  
  foreach (HtmlElement link in links)  // this ex is given another SO post 
  {
      if (link.InnerText.Equals("My Assigned"))
          link.InvokeMember("Click");
  }
  </code></pre>
  
  <p>Can any body suggest how to do it ??</p>
  
  <p>Solved :</p>
  
  <p>I changed to <code>HtmlElementCollection links = webBrowser.Document.GetElementsByTagName("A");</code>  to <code>HtmlElementCollection links = webBrowser1.Document.Links</code>  and used </p>
  
  <pre><code> if (link.InnerText.Contains("My Assigned"))
  {
          link.InvokeMember("Click");
  }
  </code></pre>
  
  <p>. any one who better solution?</p>