/// <summary> /// Related search. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnRelatedSearch_Click(object sender, EventArgs e) { string query = tbQueryString.Text; // Create a Bing container. string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results. var relatedQuery = bingContainer.RelatedSearch(query, null, market, null, null, null); relatedQuery = relatedQuery.AddQueryOption("$top", 10); // Run the query and display the results. var relatedResults = relatedQuery.Execute(); List <Bing.RelatedSearchResult> relatedSearchResultList = new List <Bing.RelatedSearchResult>(); Label lblResults = new Label(); StringBuilder searchResults = new StringBuilder(); foreach (Bing.RelatedSearchResult rResult in relatedResults) { searchResults.Append(string.Format("<a href={1}>{0}</a><br /> {1}<br />", rResult.Title, rResult.BingUrl)); } lblResults.Text = searchResults.ToString(); Panel1.Controls.Add(lblResults); }
static void MakeRelatedRequest(string question) { // This is the query expression. string query = question; // Create a Bing container. string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // The market to use. string market = "en-us"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 5 results. var relatedQuery = bingContainer.RelatedSearch(query, null, market, null, null, null); relatedQuery = relatedQuery.AddQueryOption("$top", 5); // Run the query and display the results. var relatedResults = relatedQuery.Execute(); foreach (var result in relatedResults) { Console.WriteLine("{0}\n\t{1}", result.Title, result.BingUrl); } }
static void MakeRelatedRequest(string question) { // This is the query expression. string query = question; // Create a Bing container. string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // The market to use. string market = "en-us"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 5 results. var relatedQuery = bingContainer.RelatedSearch(query, null, market, null, null, null); relatedQuery = relatedQuery.AddQueryOption("$top", 5); // Run the query and display the results. var relatedResults = relatedQuery.Execute(); foreach (var result in relatedResults) { Console.WriteLine("{0}\n\t{1}", result.Title, result.BingUrl); } }