Click here to Skip to main content
13,141,157 members (54,394 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi all,

Scenario:
I have a windows application with a Web Browser control in it.
There are hundreds of links in that web page, each linking to different documents.
On the click of every link, the document loads in the same webpage.

Now here is the question:
Is there a way so that after the web page is loaded completely, each of the link click event in the page is raised and hence the corresponding documents (which is nothing but 'href' of the links) are saved in a specified location in the computer.
[either through threading or else one after another]

Below is a little progress from my side.

protected void doc_completed(object sender, WebBrowserDocumentCompletedEventArgs e)
       {          
           HtmlElementCollection mylinks = mywebBrowser.Document.GetElementsByTagName("A");
Posted 29-Sep-12 10:59am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You can always use Html Agility Pack.

HtmlWeb hw = new HtmlWeb();
 HtmlDocument doc = hw.Load(/* url */);
 foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href]"))
 {
 
 }
 
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I used the asyn file download function to download all the files that were linked in the web page.


foreach(HtmlElement single_link in mylinks)
{
 WebClient client = new WebClient();
 client.DownloadFileAsync(new Uri("SomeURLToFile"),"SomePlaceOnLocalHardDrive");
}
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 1 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100