Click here to Skip to main content
6,597,576 members and growing! (23,946 online)
Email Password   helpLost your password?
Languages » C / C++ Language » General     Intermediate

Google Web Service Client program

By Wooseok Seo

A very simple client program that uses Google's web service
C#, Windows, .NET 1.0, Dev
Posted:27 Apr 2002
Views:118,156
Bookmarked:56 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
19 votes for this article.
Popularity: 4.70 Rating: 3.68 out of 5
2 votes, 16.7%
1
1 vote, 8.3%
2

3
1 vote, 8.3%
4
8 votes, 66.7%
5

Sample Image

This is very simple client program that uses Google's web service. You can download the SDK from Google.

The sample code is like the following.

private void buttonSearch_Click(object sender, System.EventArgs e)
{
    // before search

    //

    labelSearchText.Text = "Searching...";
    labelSearchText.Update();


    // create Google Search object

    //

    GoogleSearchService s = new GoogleSearchService();
    GoogleSearchResult r;


    // call search function

    //

    r = s.doGoogleSearch(
        "",  ; You license key!
        textSearch.Text, 
        0, 
        10, 
        false, "", false, "", "", "");


    // create HTML document to show result

    //

    string strFile = "result.html";
    StreamWriter sw = File.CreateText(strFile);


    // Header inforamtion

    //

    sw.WriteLine("<HTML><HEAD></HEAD><BODY>");


    // Category 

    //

    foreach(DirectoryCategory dc in r.directoryCategories)
    {
        sw.Write("<b>Category</b> : ");
        sw.WriteLine(dc.fullViewableName);
        sw.WriteLine("<br><br><br>");
    }


    // iterate items

    //

    foreach(ResultElement re in r.resultElements)
    {
        // Title

        //

        string strTitle = "<a href=\"" + re.URL + "\">" + 
                          re.title + "</a><br>";
        sw.WriteLine(strTitle);
        
        // snippet

        //

        string strSnippet = re.snippet +"<br>";
        sw.WriteLine(strSnippet);

        // link and cache size

        //

        string strLink = "<a href=\"" + re.URL + "\">" + re.URL + "</a> - " 
                         + re.cachedSize + "<br><br>";
        sw.WriteLine(strLink);

        // 2 line

        //

        sw.WriteLine("<br><br>");
    }


    // file close

    //

    sw.Close();

    
    // result inforamtion

    //

    labelSearchText.Text = textSearch.Text + " 's web search";

    int estResults = r.estimatedTotalResultsCount;
    double ldTime = r.searchTime;
    labelSearchResult.Text = "Total " + Convert.ToString(estResults) + "  " + 
                    "1 - 10 seach result  Total time:" + 
                                         Convert.ToString(ldTime);


    // browsing!

    //

    object obj = null;
    DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
    string strFilePath = di.FullName + "\\" + strFile;
    WebBrowser.Navigate(strFilePath, ref obj, ref obj, ref obj, ref obj);
}


// Google API homepage
//
private void linkLabel1_LinkClicked(object sender, 
                      System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
    object obj = null;

    WebBrowser.Navigate("http://www.google.com/apis/", ref obj, ref obj, 

                        ref obj, ref obj);
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Wooseok Seo


Member
Woo Seok Seo have been a Microsoft MVP for 7 years and have translated several books into Korean. Author of C# Programming for Beginner (DevPress, 2001), he is interested in Debugging techniques and .NET technology. Get in touch with Woo Seok Seo at wooseok.seo@gmail.com
Occupation: Software Developer (Senior)
Location: Korea, Republic Of Korea, Republic Of

Other popular C / C++ Language articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 24 of 24 (Total in Forum: 24) (Refresh)FirstPrevNext
GeneralSerial key PinmemberBill_IT17:39 5 Apr '09  
GeneralRe: Serial key PinmemberUmass7:18 3 Jun '09  
GeneralRe: Serial key Pinmemberswdev.bali19:38 23 Jun '09  
Generalgoogle api PinmemberMachvi11:42 31 May '08  
Generalthanks very much Pinmemberbabylon12847:40 4 Apr '07  
QuestionLicense key PinmemberBHAVANA RAO0:25 28 Mar '07  
AnswerRe: License key PinmemberWooseok Seo1:27 28 Mar '07  
GeneralRe: License key Pinmembernip9022:48 28 Mar '07  
GeneralRe: License key PinmemberUmass7:17 3 Jun '09  
GeneralRe: License key Pinmembernip908:09 3 Jun '09  
QuestionException Pinmembersir Beans2:26 8 Sep '06  
QuestionDataBinder.Eval() PinmemberTheEagle23:14 29 Jun '06  
GeneralNeed Help Pinmemberovia1:56 28 Sep '05  
GeneralHelp..... PinmemberWiele Met 'n P3:02 23 Sep '03  
Generalthanks Pinmemberayman15:52 2 Jun '03  
GeneralRe: thanks PinmemberMahmoud Nasr Ahmed23:55 3 Jun '03  
GeneralNiiice Pinmemberkeno17:33 5 Sep '02  
GeneralDemo Froze up everytime PinmemberSoliant10:03 20 Aug '02  
GeneralGood Job Pinmemberkromozom4:34 16 Aug '02  
General[Smile] Cool job! PinmemberSmile Seo20:33 28 Apr '02  
GeneralRe: [Smile] Cool job! PinmemberNish [BusterBoy]20:41 28 Apr '02  
GeneralRe: [Smile] Cool job! Pinmemberasuleman23:12 18 Apr '03  
GeneralRe: [Smile] Cool job! PinmemberSmile Seo5:44 29 Jun '03  
GeneralRe: [Smile] Cool job! Pinmemberguy kolb4:29 18 Apr '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Apr 2002
Editor: Chris Maunder
Copyright 2002 by Wooseok Seo
Everything else Copyright © CodeProject, 1999-2009
Web21 | Advertise on the Code Project