Google web service in web application

I have a google search web service working in my application but want to restrict the search to just my site.  But I can't work out where to put the url address.

Dim gs As New
        Dim r As = gs.doGoogleSearch(key, txtSearch.Text, 0, 10, True, "countryUK", False, "lang_en", "", "")
Any suggestions?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Can you take a look at this page.

See View code. They had done it with setting the target and hidden fields only. -->Go here and click search link on the top right corner.


Lookout this article.

Peter Bromberg had commentted atlast in his article.

"If you wanted to, you could get pretty sophisticated with this. One idea is to create a usercontrol that can simply be plugged into a web page at the location of your choice. You can also use the tool to restrict the search to only a particular site (like their "put Google Search on your site" feature) so that it only searches on your site."

Hope you got it.
I guess you can use this url to refer for your query.

You need to restrict google search to only your site.
There is a feature call "Site restriction"
Under above url look for "Special Query Terms"
In that topic there are details.

Site Restricted Search


If you know the specific web site you want to search but aren't sure where the information is located within that site, you can use Google to search only within a specific web site.
Do this by entering your query followed by the string "site:" followed by the host name.

Note: The exclusion operator ("-") can be applied to this query term to remove a web site from consideration in the search.

Note: Only one site: term per query is supported.

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

I had this code tested and ran you just replace key with your own key value

<%@ Import Namespace="System.Text" %>
<Script Language="VB" Runat="Server">

Dim key As String="your key goes here", _
      maxResults As Integer, _
      formatString As String="<p><a href=""{1}"">{0}</a><br>{2}<br>{1}-{3}</p>"
Sub Page_Load(s As Object, e As EventArgs)
      If Not IsPostBack Then
      End If
End Sub

Sub Search(s As Object, e As EventArgs)
      resultlist.Text=doQuery(searchtext.Text, 0)
End Sub

Function doQuery(st As String, rc As Integer)
      Dim totalcount As Integer, _
            displaytitle As String, _
            sb As StringBuilder=New StringBuilder()
      Dim s As GoogleSearchService=New GoogleSearchService(), _
            r As GoogleSearchResult=s.doGoogleSearch( _
                  key, st, rc, maxresults, false, "", false, "", "", "")
      Dim result As ResultElement
      For Each result In r.resultElements
            If result.title <> "" Then
            End If
            sb.Append(String.Format( _
                  formatString, displayTitle, result.URL, result.snippet, result.cachedSize))
      If r.estimateIsExact And r.endIndex >= totalCount Then
      End If
      If rc=0 Then
      End If
      Return sb.ToString()
End Function

Sub NextClick(s As Object, e As EventArgs)
      resultList.Text=doQuery(searchtext.Text, Session("CurrentRecord"))
End Sub

Sub PreviousClick(s As Object, e As EventArgs)
      resultList.Text=doQuery(searchtext.Text, Int32.Parse(Session("CurrentRecord")))      
End Sub

<TITLE>Google API Example</TITLE>

<form runat="server">
            Google Search: <asp:textbox id="searchtext" runat="server" />
            <asp:button id="btn1" text="Search" runat="server" onclick="search" />
      <asp:panel id="headerpanel" runat="server">
                  <asp:label id="lblresults" runat="server" text="Total Results Returned:" />
                  <asp:label id="lbltotalresults" runat="server" />
                  <asp:label id="resultlist" runat="server" />
                  <asp:linkbutton id="lbprev" onclick="previousclick" visible="false" runat="server">Previous</asp:linkbutton>
                  <asp:linkbutton id="lbnext" onclick="nextclick" visible="false" runat="server">Next</asp:linkbutton>

you can also test and debug web services by using Web Services Studio
this tool will show you everything in details about what some particular WS requires, it made lots of thing very easy for me...
ladykhAuthor Commented:
This is the code for when I click the search button and it works to search many sites, but I still cannot get is to search one site?

Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        Const key As String = "google key"

        Dim gs As New
        Dim r As = gs.doGoogleSearch(key, txtSearch.Text, 0, 10, True, "countryUK", False, "lang_en", "", "")
        Dim x As Integer
        Dim dt As New GoogleResultElement.ResultElementDataTable()
        If r.startIndex = r.endIndex Then
            lblGoogleMessage.Text = "No Results Found"
            For x = r.startIndex - 1 To r.endIndex - 1
                Dim dr As GoogleResultElement.ResultElementRow = dt.NewResultElementRow
                Dim re As = r.resultElements(x)
                dr.summary = re.summary
                dr.URL = re.URL
                dr.snippet = re.snippet
                dr.title = re.title
                dr.CachedSize = re.cachedSize
                dr.relatedInformationPresent = re.relatedInformationPresent
                dr.hostName = re.hostName
                dr.directoryCategory = re.directoryCategory.fullViewableName
                dr.directoryTitle = re.directoryTitle
            DataGrid1.DataSource = dt
            lblGoogleMessage.Text = r.searchComments
        End If
    End Sub
> but I still cannot get is to search one site?

I don't get it...
ladykhAuthor Commented:
I just need it to search the pages in the website I am creating, not all of google. If this is possible?
ok, now I think I got you now... are you trying to search your site using google web service..? I think it depends how much info google has about your site, however you can use MS Index Server or any other third party software for your site. There is also a cool feature that you can integrate into your website, here just copy and paste

<FORM method=GET action="">
<input type=hidden name=ie value=UTF-8>
<input type=hidden name=oe value=UTF-8>
<TABLE bgcolor="#FFFFFF"><tr><td>
<A HREF="">
border="0" ALT="Google"></A>
<INPUT TYPE=text name=q size=31 maxlength=255 value="">
<INPUT type=submit name=btnG VALUE="Google Search">
<font size=-1>
<input type=hidden name=domains value="PUT YOUR DOMAIN NAME HERE"><br><input type=radio name=sitesearch value=""> WWW <input type=radio name=sitesearch value="PUT YOUR DOMAIN NAME HERE" checked> PUT YOUR DOMAIN NAME HERE <br>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ladykhAuthor Commented:
Thanks for your help.
you're welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.