Google Search using Page Viewer Web Part on SharePoint 2010

If you ever tried adding Google Search code that will search your site to a SharePoint page using the HTML Form web part, you might get an error like this:

Unexpected System.NullReferenceException: Object reference not set to an instance of an object.   at Microsoft.SharePoint.WebPartPages.WikiPageWebPartSaver.SaveWebPartsInRichText(SPWebPartManager wpmgr)

A simple way to add the Google Search for your site is to use the Page Viewer Web Part and reference an HTML file with the Google Search form code:

 <!-- Search Google --> 
<font color="#006633" size="+1" face="Times New Roman">Search</font> 
<center> 
<FORM action=http://www.google.com/u/ursite method=GET target="_blank"> 
<!--mstheme--></font>
<TABLE bgcolor=#FFFFFF cellspacing=0 border=0><tr valign=middle><td><!--mstheme--><font face="Times New Roman"> 
<A HREF=http://www.google.com/ > 
<IMG SRC="http://www.google.com/logos/Logo_40wht.gif" border=0 ALT=Google width="128" height="53"></A> <!--mstheme--></font></td> 
<td><!--mstheme--><font face="Times New Roman"> 
<INPUT TYPE=text name=q size=31 maxlength=255 value=""> 
<INPUT type=submit name=sa VALUE="Google Search" > 
<input type=hidden name=hq value="inurl:www.YourSite.com/subsite" > 
<font face=arial,sans-serif size=-1><br><input type=hidden name=sitesearch value="YourSite.com" checked> 
</font><br> 
<!--mstheme--></font></td></tr></TABLE>
<!--mstheme--><font face="Times New Roman">    
</FORM> 
</center> 
<!-- Search Google --> 

Add the file to the sub folder under LAYOUTS:  \Web Server Extensions\14\TEMPLATE\LAYOUTS\Custom\google.html

Then, add a Page Viewer Web Part (Under Media and Content) to a page and set the Web Page property to http://ServerName/_layouts/custom/google.html

image

Note: You may have to allow the search to open in a new window.

  1. Leave a comment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: