How to Search News in Google Using ASP.Net


This article explains how to search the news in Google using ASP.NET.

In this article we will use the GoogleSearchAPI to find today's news based on the keywords used.

Step 1

First start a new project in ASP.NET and name it as "GoogleNews".


Step 2

Now add a new web page to your application and again name it "GoogleNews".


Now you need to add a DLL for Google News, you can find the DLL in the file attached to this article.


Step 3

Now you need to add the following code to your application:


    <form id="form1" runat="server">


        <asp:TextBox ID="SearchBox" runat="server" Width="300px"></asp:TextBox>

        <asp:Button ID="btnSearch" runat="server"

        Text="See Today's News" OnClick="Button1_Click"/><br />

        <asp:DataList ID="dtlist" runat="server" Width="600px">


                <asp:LinkButton ID="lnk" runat="server" Text='<%#Eval("Heading") %>' PostBackUrl='<%#Eval("Path") %>'></asp:LinkButton><br />

                <asp:Label ID="Lbl1" runat="server" Text='<%#Eval("Data") %>'></asp:Label><br/>

                <img src='<%#Eval("Pic") %>'  width="100px" height="80px" /><br />

                <asp:Label ID="Lbl2" runat="server" Text='<%# "(Publisher:"+Eval("Publisher")+")"+ Eval("Date") %>'></asp:Label>

                <br />



                <asp:Label Visible='<%#bool.Parse((dtlist.Items.Count==0).ToString())%>' runat="server" ID="NoNews" Text="Sry, No News"></asp:Label>






This will add a TextBox, a Button and a DataList to your application.

Three more things are used in this application, these are:

  1. A Link Label to show the title of the search results.
  2. An Image Control to show the image of the news.
  3. And a Label to show the Publisher Name and the date of the news.

Your application will now have a design like this:


Step 4

Add these two namespaces to your project:

using Google.API.Search;

using System.Data;

After adding these namespaces, add the following code to your application:

        protected void Page_Load(object sender, EventArgs e)


            if (!IsPostBack)


                dtlist.DataSource = null;


                SearchBox.Text = "";




        protected void Button1_Click(object sender, EventArgs e)


            DataSet dts = new DataSet();

            DataTable data = new DataTable();

            data.Columns.Add(new DataColumn("Heading", typeof(string)));

            data.Columns.Add(new DataColumn("Data", typeof(string)));

            data.Columns.Add(new DataColumn("Path", typeof(string)));

            data.Columns.Add(new DataColumn("Pic", typeof(string)));

            data.Columns.Add(new DataColumn("Publisher", typeof(string)));

            data.Columns.Add(new DataColumn("Date", typeof(string)));

            GnewsSearchClient client = new GnewsSearchClient("");

            IList<INewsResult> results = client.Search(SearchBox.Text, 30);

            foreach (INewsResult result in results)


                DataRow dtr = data.NewRow();

                dtr["Heading"] = result.Title.ToString();

                dtr["Data"] = result.Content.ToString();

                dtr["Path"] = result.Url;

                dtr["Pic"] = result.Image;

                dtr["Publisher"] = result.Publisher;

                dtr["Date"] = result.PublishedDate;



            dtlist.DataSource = data;



This code will send the value of the text box to the Google Server, on getting the results it will be bound to the DataTable and then to the DataList.


It's final output will be as follows:


First a blank TextBox will be available in which you need to enter the Keyword by which you want to search the news.

After providing the keyword, click on the Button in front of it.