Click here to Skip to main content
15,669,526 members
Articles / Programming Languages / C#
Posted 14 Jul 2008

Tagged as


19 bookmarked

SharePoint Search Integration with Google

Rate me:
Please Sign up or sign in to vote.
3.80/5 (12 votes)
14 Jul 2008CPOL
This solution helps to view SharePoint search results along with Google results within a SharePoint portal.

Image 1


This solution helps to view SharePoint search results along with Google results within a SharePoint portal.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SharepointGoogleSearchIntegration : System.Web.UI.UserControl
    #region PageLoad
    /// <summary>
    /// This is an aspx page,hosted in SharePoint
    /// which renders the search results depending 
    /// on the query string passed from the SharePoint WebPart.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
        ///Here the query string is fetched & is passed to a hidden varible , which in turn 
        ///passes the value to the Google-API to fetch the corresponding search results.
        //Since Sharepoint uses K as the querystring parameter , due to which we have used 
        // K as the Query String parameter , so that same query is used for Portal Search 
        //along with With Search
        if ((Request.QueryString["k"] != null) && 
            ((Request.QueryString["k"] != "")))
            //This is the hidden field which is used as a container for the value
            //fetched from the query string . 
            hdnField.Value = Request.QueryString["k"].ToString();
            hdnField.EnableViewState = true;



    /// <summary>
    /// This method is used to pass the server side value to the 
    /// client side variable
    /// </summary>
    protected void InitalizeScripts()
        String sb = string.Empty;
        // Underneath is the JavaScript which is truncated here & will be 
        // visible when you will download the article.
        sb = "<script type='text/javascript' language="'javascript'">"
        + "function LoadValues()"
        + "{"
        + "var hiddenval = '" + hdnField.Value + "';"
        + "return hiddenval;"     
        + "}" 

        Page.RegisterClientScriptBlock("ClientScript", sb.ToString());

SharePoint - Google - Search Integration allows the user to view the web results within the SharePoint portal. The user doesn't need to specify the text separately into two search controls. The default SharePoint Search WebPart is used to pass the query to other WebParts which produce the web results at the same time.

In case of any queries, you can revert to me at "" or "".


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Other Microsoft
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralSharePoint Search Integration with Google Pin
Member 1000438922-Apr-13 2:33
Member 1000438922-Apr-13 2:33 
GeneralSize of the Google Results Pin
kishore_sharepoint21-Oct-10 19:40
kishore_sharepoint21-Oct-10 19:40 
QuestionError when adding part... Pin
Member 28654845-Sep-08 9:05
Member 28654845-Sep-08 9:05 
I added this control to the usercontrols directory, when I add a smart part to a page, then choose the sharepointgooglesearchintegration control, I get an error:

The name 'hdnField' does not exist in the current context

Any idea on how to resolve? Im using smartpart version 1.3.
AnswerRe: Error when adding part... Pin
Pankaj Pahuja - MCTS - Sharepoint 20106-Sep-08 21:32
Pankaj Pahuja - MCTS - Sharepoint 20106-Sep-08 21:32 
QuestionHow to use it? Pin
wintert19-Jul-08 23:45
wintert19-Jul-08 23:45 
AnswerRe: How to use it? Pin
Pankaj Pahuja - MCTS - Sharepoint 201020-Jul-08 18:50
Pankaj Pahuja - MCTS - Sharepoint 201020-Jul-08 18:50 
JokeVery Good job Pin
Suchithra Deenam15-Jul-08 22:33
Suchithra Deenam15-Jul-08 22:33 
GeneralGood Idea! Pin
Sohel_Rana15-Jul-08 1:03
Sohel_Rana15-Jul-08 1:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.