Archive for April, 2012

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> 
<FORM action= method=GET target="_blank"> 
<TABLE bgcolor=#FFFFFF cellspacing=0 border=0><tr valign=middle><td><!--mstheme--><font face="Times New Roman"> 
<A HREF= > 
<IMG SRC="" 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="" > 
<font face=arial,sans-serif size=-1><br><input type=hidden name=sitesearch value="" checked> 
<!--mstheme--><font face="Times New Roman">    
<!-- 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


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

Leave a comment