Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
4.00/5 (1 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.

C#
protected void doc_completed(object sender, WebBrowserDocumentCompletedEventArgs e)
       {          
           HtmlElementCollection mylinks = mywebBrowser.Document.GetElementsByTagName("A");
Posted

You can always use Html Agility Pack.

C#
HtmlWeb hw = new HtmlWeb();
 HtmlDocument doc = hw.Load(/* url */);
 foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href]"))
 {

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


C#
foreach(HtmlElement single_link in mylinks)
{
 WebClient client = new WebClient();
 client.DownloadFileAsync(new Uri("SomeURLToFile"),"SomePlaceOnLocalHardDrive");
}
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900