Introduction
This blog I am going to describe how to retrieve gmail contact with Name and Mail id in asp net. Here I will describe how to communicate with Gmail using Google API.
Description
As it is a third party software for this we required some third party dll to be referenced to our application which will communicate with Gmail server.
For this we have to download the Google API Set up from below link
http://code.google.com/p/google-gdata/
Or you can direct download from this link
https://google-gdata.googlecode.com/files/Google_Data_API_Setup_2.1.0.0.msi
Install this setup you will get these dll files in your Pc
- Google.GData.Apps.dll
- Google.GData.Client.dll
- Google.GData.Contacts.dll
- Google.GData.Extensions.dll
Collect these dll's.
Design
Now design your design the screen as below screen

Or Copy the source code below
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE
html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html
xmlns="http://www.w3.org/1999/xhtml">
<head
runat="server">
<title></title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
<table
align="center"
width="100%">
<tr>
<td>
<table
align="center">
<tr></tr>
<tr>
<td>
<asp:Label
ID="Label1"
runat="server"
Text="User name"></asp:Label>
</td>
<td>
<asp:TextBox
ID="txtName"
runat="server"
Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label
ID="Label2"
runat="server"
Text="Password"></asp:Label>
</td>
<td>
<asp:TextBox
ID="txtPwd"
runat="server"
TextMode="Password"
Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td
colspan="2"
align="center">
<asp:Button
ID="btnLogin"
runat="server"
Text="Get Contact"
OnClick="btnLogin_Click"
/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td
align="center">
<asp:GridView
ID="gvContacts"
runat="server"
EmptyDataText="No
contacts" AllowPaging="true"
Width="50%"
PageSize="15"
AutoGenerateColumns="false"
OnPageIndexChanging="gvContacts_PageIndexChanging">
<Columns>
<asp:TemplateField
HeaderText="Contact
Name">
<ItemTemplate>
<asp:Label
ID="lblName"
runat="server"
Text='<%#Eval("Name")
%>'></asp:Label>
</ItemTemplate>
<ItemStyle
Width="200px"
/>
</asp:TemplateField>
<asp:TemplateField
HeaderText="Contact
Email">
<ItemTemplate>
<asp:Label
ID="lblEmail"
runat="server"
Text='<%#Eval("EmailID")
%>'></asp:Label>
</ItemTemplate>
<ItemStyle
Width="100px"
/>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Next add reference of Google gdata
dll to your website.
- Google.GData.Apps.dll
- Google.GData.Client.dll
- Google.GData.Contacts.dll
- Google.GData.Extensions.dll
And write the below code .cs file
using
System;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
Google.GData.Contacts;
using
Google.GData.Client;
using
Google.GData.Extensions;
using
Google.Contacts;
public
partial class
_Default : System.Web.UI.Page
{
public DataSet
GetGmailContacts(string AppName,
string Uname, string
UPassword)
{
DataSet ds =
new DataSet();
DataTable dt =
new DataTable();
dt.Columns.Add(new
DataColumn("EmailID",
typeof(string)));
dt.Columns.Add(new
DataColumn("Name",
typeof(string)));
RequestSettings rs =
new RequestSettings(AppName,
Uname, UPassword);
rs.AutoPaging = true;
ContactsRequest cr =
new ContactsRequest(rs);
Feed<Contact>
f = cr.GetContacts();
foreach (Contact
t in f.Entries)
{
foreach (EMail
email in t.Emails)
{
DataRow dr1 = dt.NewRow();
dr1["EmailID"] =
email.Address.ToString();
dr1["Name"] =
t.Title.ToString();
dt.Rows.Add(dr1);
}
}
ds.Tables.Add(dt);
return ds;
}
protected void
Page_Load(object sender,
EventArgs e)
{
}
protected void btnLogin_Click(object
sender, EventArgs e)
{
DataSet ds = GetGmailContacts("Gmail
Contact Operations!", txtName.Text, txtPwd.Text);
ViewState["Contact"] = ds;
gvContacts.DataSource = ds;
gvContacts.DataBind();
}
protected void
gvContacts_PageIndexChanging(object sender,
GridViewPageEventArgs e)
{
DataSet ds = ViewState["Contact"]
as DataSet;
gvContacts.PageIndex = e.NewPageIndex;
gvContacts.DataSource = ds;
gvContacts.DataBind();
}
}
Now build your Application. And enter Gmail id and password in the corresponding
textbox
Click on Get Contact button it will show all your gmail Contact Name with Email.

Any modification or problem Plz comment.

Sunil DeshalahrePosted Nov 15, 2016, 6:54 AM
I am getting exeption "Execution of authentication request returned unexpected result: 404"
lalita gopalePosted Mar 29, 2016, 2:14 AM
i got this error "Execution of request failed: http://www.google.com/m8/feeds/contacts/default/full"
sonal gargPosted Sep 9, 2015, 4:21 AM
i have download this code but this error is shown : The type or namespace name 'google' could not be found (are you missing a using directive or an assembly reference?)
Sanjeeb LenkaPosted Jun 5, 2013, 3:21 AM
i checked all the code its it working............
Jolly PriyaPosted Jun 5, 2013, 1:56 AM
i tried but again same error..invalid credentials...whereas i m able to login in google accounts by same credentilas
Sanjeeb LenkaPosted Jun 4, 2013, 8:05 AM
wirte%20your%20full%20gmail%20id%20ex-%[email protected]%20and%20pwd
Sanjeeb LenkaPosted Jun 4, 2013, 8:01 AM
chcke%20once%20in%20login%20in%20google%20account
Jolly PriyaPosted Jun 4, 2013, 7:39 AM
error%20%3Ainvalid%20credentials...but%20my%20credentials%20are%20100%25%20right
Jolly PriyaPosted Jun 4, 2013, 7:28 AM
error%3A%20System.Net.WebException%3A%20The%20remote%20name%20could%20not%20be%20resolved%3A%20%27www.google.com%27
Jolly PriyaPosted Jun 4, 2013, 7:27 AM
i%20m%20not%20getting%20the%20output..
Sanjay KumarPosted Jun 4, 2013, 3:44 AM
Nice
kid nguyenPosted Jun 3, 2013, 9:17 PM
Very%20good
Sanjeeb LenkaPosted Jun 3, 2013, 2:11 PM
thanx%20all
BalaPosted Jun 3, 2013, 7:06 AM
nice%20to%20know%20new%20information
Sharad GuptaPosted Jun 3, 2013, 5:53 AM
nice%20one....