Archive for April, 2012
Google Search using Page Viewer Web Part on SharePoint 2010
Posted by Jake in SharePoint on April 30, 2012
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
Note: You may have to allow the search to open in a new window.