Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm working on a desktop application in C# forms.I need this List of Banks in a combobox as drop down list, like this one.
I've populated the combobox drop down list myself. But I want to fetch that list from the given link.I've search on google and found few answers but they are not helping.

I tried to get that data by using following code but I only got some html like contents in result.
C#
System.Net.WebClient wc = new System.Net.WebClient();
string webData = wc.DownloadString("http://www.pakwatan.pk/banks-pakistan/");
cbBankName.DataSource = webData.ToList();

I don't know how to extract require contents from result in webdata.
someone please help.
Posted
Comments
[no name] 16-Oct-15 13:14pm    
Try HtmlAgilityPack library to parse the HTML and extract the list you need. But since this is not a web service it will be very prone to error. Even small changes in the markup can break your code so it wouldn't be very reliable
ZurdoDev 16-Oct-15 13:47pm    
I'd suggest posting this as a solution, since it really does answer the question, short of doing everything for the OP.
[no name] 16-Oct-15 13:51pm    
Thanks for the suggestion @RyanDev. I posted as an answer. I'm new in the Q&A section of the site :-)
Nathan Minier 16-Oct-15 13:22pm    
Get a sample of the result and make your parsing decisions. If it's XML, JSON, or CSV that's easy money, just use a built-in parser. Otherwise you might need to write your own.
ZurdoDev 16-Oct-15 13:47pm    
As Volkan said, this is prone to errors but you'll have to scrape through the html and try to find what you need. Or, ask the admin of that site to build you a webservice that exposes what you need.

1 solution

Try HtmlAgilityPack library (download from https://htmlagilitypack.codeplex.com[^] or as a NuGet package) to parse the HTML and extract the list you need. But since this is not a web service it will be very prone to error. Even small changes in the markup can break your code so it wouldn't be very reliable.
 
Share this answer
 
Comments
ZurdoDev 16-Oct-15 14:34pm    
+5. Good answer.
Ammar Shaukat 16-Oct-15 16:16pm    
I've download this library but how to use it ?
[no name] 16-Oct-15 16:27pm    
It's a popular library. Just search "htmlagilitypack example" and you'll get plenty of resources
Ammar Shaukat 16-Oct-15 16:28pm    
okay.. thanks..
BillWoodruff 17-Oct-15 2:41am    
+5

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