Google Patent Search in ASP.Net

Introduction

This article describes how to add a Google Patent search feature in ASP.Net. Here I will describe how to communicate with the Google Search API.

Description

Since it is third party software, we require a third-party DLL to be referenced by our application that will communicate with the Google server.

For this we must download the Google Search API:

  1. GoogleSearchAPI.dll

You can download it from the source code attached to this article.

Or from this link: http://google-api-for-dotnet.googlecode.com/files/GoogleSearchAPI_0.3.1.zip

Design

Now add one TextBox, one Button and one Datalist.

In the Datalist I used one Linkbutton to show the search result title and  Image control to show the Image. Two label one for show Content and Another for show Status, Application date and Patent Number.

Design your screen as in the following screen.



Or you can copy the following source code:
  1. <body>  
  2.     <form id="form2" runat="server">  
  3.     <div>  
  4.         <asp:TextBox ID="TextBox1" runat="server" Width="300px"></asp:TextBox>  
  5.         <asp:Button ID="btnSearch" runat="server" Text="Google Patent Search" OnClick="Button1_Click" /><br />  
  6.         <asp:DataList ID="dlSearch" runat="server" Width="600px">  
  7.             <ItemTemplate>  
  8.                 <asp:LinkButton ID="LinkButton1" runat="server" Text='<%#Eval("Title")+"("+Eval("Assignee")+")" %>' PostBackUrl='<%#Eval("Url") %>'></asp:LinkButton><br />  
  9.                 <asp:Label ID="Label1" runat="server" Text='<%#Eval("Content") %>'></asp:Label><br />  
  10.                 <img src='<%#Eval("Image") %>' /><br />  
  11.                 <asp:Label ID="Label2" runat="server" Text='<%# "(Status:-"+Eval("Status")+", Patent Number:-"+Eval("PatentNumber")+",Application Date:-"+Eval("Date") +")"%>'></asp:Label>  
  12.                 <br />  
  13.             </ItemTemplate>  
  14.             <FooterTemplate>  
  15.                 <asp:Label Visible='<%#bool.Parse((dlSearch.Items.Count==0).ToString())%>' runat="server" ID="lblNoRecord" Text="No Record Found!"></asp:Label>  
  16.             </FooterTemplate>  
  17.         </asp:DataList>  
  18.     </div>  
  19.     </form>  
  20. </body>
Now go to the code view.

Next add a reference of the following Google Search API DLL to your website:
  1. GoogleSearchAPI.dll
And write the following code in the .cs file:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Data;  
  8. using Google.API.Search;  
  9. public partial class GooglepatentSearch : System.Web.UI.Page  
  10. {  
  11.     protected void Page_Load(object sender, EventArgs e)  
  12.     {  
  13.         if (!IsPostBack)  
  14.         {  
  15.             dlSearch.DataSource = null;  
  16.             dlSearch.DataBind();  
  17.             TextBox1.Text = "";  
  18.         }  
  19.     }  
  20.     protected void Button1_Click(object sender, EventArgs e)  
  21.     {  
  22.         DataSet ds = new DataSet();  
  23.         DataTable dt = new DataTable();  
  24.         dt.Columns.Add(new DataColumn("Title"typeof(string)));  
  25.         dt.Columns.Add(new DataColumn("Url"typeof(string)));  
  26.         dt.Columns.Add(new DataColumn("Image"typeof(string)));  
  27.         dt.Columns.Add(new DataColumn("Status"typeof(string)));  
  28.         dt.Columns.Add(new DataColumn("Content"typeof(string)));  
  29.         dt.Columns.Add(new DataColumn("Assignee"typeof(string)));  
  30.         dt.Columns.Add(new DataColumn("PatentNumber"typeof(string)));  
  31.         dt.Columns.Add(new DataColumn("Date"typeof(string)));  
  32.         GpatentSearchClient client = new GpatentSearchClient("www.c-sharpcorner.com");  
  33.         IList<IPatentResult> results = client.Search(TextBox1.Text, 30);  
  34.         foreach (IPatentResult result in results)  
  35.         {  
  36.             DataRow dr = dt.NewRow();  
  37.             dr["Title"] = result.Title.ToString();  
  38.             dr["Url"] = result.Url;  
  39.             dr["Image"] = result.TbImage;  
  40.             dr["Status"] = result.PatentStatus;  
  41.             dr["Content"] = result.Content;  
  42.             dr["Assignee"] = result.Assignee;  
  43.             dr["PatentNumber"] = result.PatentNumber;  
  44.             dr["Date"] = DateTime.Parse(result.ApplicationDate.ToString()).ToString("dd MMM yyyy");  
  45.             dt.Rows.Add(dr);  
  46.         }  
  47.         dlSearch.DataSource = dt;  
  48.         dlSearch.DataBind();  
  49.     }  
  50. }   

In the code above I passed the TextBox value in the button click to the Google server.

After getting the result I bound it to the datatable then to the datalist control.

Just check these two lines:

  1. GpatentSearchClient client = new GpatentSearchClient("www.c-sharpcorner.com");  
  2. IList<IPatentResult> results = client.Search(TextBox1.Text, 30);  

In the first line I am passing "www.c-sharpcorner.com" as the Client because it required a hosted site for security purposes.

If you don't pass that then it will show an exception.

In the second line I am passing 30 and a TextBox value. Here 30 specifies to get 30 search results.

So you can increase or decrease this value as needed.

Now build your application. Enter a search query then press the button.

It will show all the Google Patent search results.

Click on the Patent Title to see the Details.


Similar Articles