Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8896317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:00:45+00:00 2026-06-15T00:00:45+00:00

private void button1_Click(object sender, EventArgs e) { test(); } public void test() { Dictionary<string,

  • 0
    private void button1_Click(object sender, EventArgs e)
    {
        test();
    }


    public void test()
    {

        Dictionary<string, string> LnksDict = new Dictionary<string, string>();

        using (SmartWebClient smwc = new SmartWebClient())
        {

            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(smwc.DownloadString("http://www.google.com/adplanner/static/top1000/"));
            var links = htmlDoc.DocumentNode
                            .Descendants("a").Select(x => x.Attributes["href"]);
            foreach (var link in htmlDoc.DocumentNode.SelectNodes("//a"))
            {
                var UrlVal= link.Attributes["href"].Value;
                var name = UrlVal.Split('.')[1];

                LnksDict.Add(name, UrlVal);
            } 
        }
    }

#region <<=========== SmWbCl ============>>

public class SmartWebClient : WebClient
{
    private readonly int maxConcurentConnectionCount;

    public SmartWebClient(int maxConcurentConnectionCount = 20)
    {

        this.maxConcurentConnectionCount = maxConcurentConnectionCount;
    }

    protected override WebRequest GetWebRequest(Uri address)
    {
        var httpWebRequest = (HttpWebRequest)base.GetWebRequest(address);
        if (httpWebRequest == null)
        {
            return null;
        }

        if (maxConcurentConnectionCount != 0)
        {
            this.Proxy = null;
            this.Encoding = Encoding.GetEncoding("UTF-8");
            httpWebRequest.ServicePoint.ConnectionLimit = maxConcurentConnectionCount;
        }

        return httpWebRequest;
    }

}

#endregion

in this code i am trying to build a list of urls to be used as autoComplete source later.

what i am doing wrong is notc onditioning on adding the parsed values into the dictionary .

i need to find a way to add domain name as the key, even if already exist,

so i would like to be able to make a condition :

if the key in this dictionary already exists, add collection index of current link to string.value of key as a suffix

or if you would like to suggest a different solution all together… i will be happy to see new example.
thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:00:46+00:00Added an answer on June 15, 2026 at 12:00 am

    I think what you want, rather than a Dictionary<string, string>, is a Dictionary<string, HashSet<string>>. That way, you can build a list of URLs for each domain. Your code to add an item to the list would be:

    var UrlVal= link.Attributes["href"].Value;
    var name = UrlVal.Split('.')[1];
    
    // get links for this host
    HashSet hostLinksList;
    if (!LnksDict.TryGetValue(name, out hostLinksList))
    {
        hostLinksList = new HashSet<string>();
        LnksDict.Add(name, hostLinksList);
    }
    // add the URL to the list of links for this host
    hostLinksList.Add(UrlVal);
    

    The key here is that calling Add on a HashSet when the item is already there won’t throw an exception. It just doesn’t add it again and returns false to indicate that the item was already in the collection.

    When you’re done, you have a list of URLs for each host (domain), which you can then use for your auto completion.

    By the way, your method of splitting out the host using Split('.') isn’t going to work very well. It assumes domains of the form “www.example.com”. If you run into, for example, “example.com” (without the “www”), you’re going to get “com” for the name. Also, “www.example.com” is going to collide with “www.example.org” and “www.example.co.uk”. You need a better way of identifying hosts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

private void button1_Click(object sender, EventArgs e) { DataTable test = getDataFromXLS(c:\temp.xls); if (test !=
private void button1_Click(object sender, EventArgs e) { for (int i = 0; i <
When I run the following code: private void button1_Click(object sender, EventArgs e) { Bitmap
I tried to login to gmail with the code: private void button1_Click(object sender, EventArgs
I have the following code: private void button1_Click(object sender, EventArgs e) { var answer
private void btnSend_Click(object sender, RoutedEventArgs e) { Button obj=(Button)sender; obj.Content=Cancel; SendImage send = new
Got this line of code here but its not working. private void Button_Click(object sender,
The following code is working great in a normal console application: private void button1_Click(object
I can't figure out why this simple update command won't work: private void button1_Click(object
click the button to call this method: private void goRegister(final boolean isUsername) { new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.