![]() |
Web Development »
Applications & Tools »
Applications
Intermediate
A completely customizable Google API Web ClientBy VasudevanmsA web based Google Web services client using ASP.NET. |
C#, VC6, VC7, VC7.1.NET 1.0, Win2K, WinXP, Win2003, ASP.NET, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

This is a demonstration of a web based client for Google Web Services. This is my first attempt at ASP.NET technology.
I have tried to make it fully customizable and open ended as far as possible.
Key customization features are:
The app looks for cfg.xml in the current working directory which would be c:\winnt\system32 by default. Copy this file to that location.
Advantage of having this is search query terms can be changed as and when requirements change, and same holds good for the results display.
This application allows a user to go through the first 1000 results since Google places that restriction.
<key/>, <ResultsPath/> and <XslPath/>. Explanation of these keys in a moment... The application sends a SOAP message to the Google Server which in turn returns a Google proprietary data structure. The application then parses this data structure and creates an XML file. (Let's call it results.xml. Note: It could be any name you choose as long as it's in the cfg.xml.) Here is a small portion of it:
<SearchResults attributes1=value1... >
<ResultSet>
<Item>
<summary />
<url>http://www.iqsoft.com/</url>
<snippet>PRODUCTIONS </snippet>
<title>Welcome to SAWStudio.com!</title>
<cachedsize>9k</cachedsize>
<relatedInformationPresent>True</relatedInformationPresent>
<hostName />
<directorytitle />
</Item>
</ResultSet>
</SearchResults>
<SearchResults>
The application then transforms this XML file using the custom stylesheet (search.xsl) and writes the results of the transformation to the client browser.
OK, so that's what the <ResultsPath/> and <XslPath/> keys mean.
<ResultsPath/> is the fully qualified path to the file where you want the app to dump the XML.
<XslPath /> is the fully qualified path to the file where the stylesheet (search.xsl) is stored. The Search class defined in the code-behind of WebForm1.aspx, which is the only webform used in the entire project, has the core function dumpResultsasXml() which does exactly as named. System.XmlTextWriter does the writing.
The Transform() function does the transformation to HTML. I have used a MemoryStream object to read the transformation results, and subsequently, a StreamReader to read that memory and convert it to string data type.
The WebForm1.getdata is where the action actually happens. This can be called from within the WebForm1.aspx like this:
<% Response.Write(getdata()) %>
There is only a single instance of the Google Search Service object which is initialized in Application_Start().
Although the "Next" and "Previous" links could have been generated by the search.xsl file, there is no way for us to control the starting index value in the XSL other than incrementing it by x like this:
<xsl:variable name="startindex" select="@currentIndex+10"/> ... and so on.
But the XSL would be blissfully unaware of what page we are on. The following code shows how it's been implemented:
if( !Page.IsPostBack)
{
start = Request.Params["start"];
results = getdata(query,Convert.ToInt32(start));
}
else
results = getdata(query,0); //In this case start would always be 0.
Tracking is done using the querystring parameter start to which x is added or subtracted, to generate the URL for the "Next " and "Previous" links. In this case, x =10. It's a good idea to have this as one of the settings in the cfg.xml, so it would be more generic. Well, next release maybe :)
Here is an example of how the Next link is generated, where start is the value of the querystring parameter start. nTotalCount is the total number of results.
if((nTotalCount - nNext) > 10)
{
Response.Write("<br></br><a href=\"webform1.aspx?type=Next&start=");
Response.Write(nNext);
Response.Write("&query=");
Response.Write(TextBox1.Text);
Response.Write("\"><b>Next</b></a><br></br>");
}
Well, I hope I have covered the key areas. Like any other program, I am certain there would be bugs and mistakes I may have made. Looking forward to your feedback so I may incorporate enhancements and bug fixes if any.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 15 Jul 2003 Editor: Smitha Vijayan |
Copyright 2003 by Vasudevanms Everything else Copyright © CodeProject, 1999-2009 Web17 | Advertise on the Code Project |