how to import Contacts from GMAIL using ASP.NET and C#

Posted by imomins on October 8, 2012 at 1:35 AM

In this article I will explain how to import gmail contacts of a user by using GContacts Data API provided by Google.


We have developed one social network site at that time we think that how to popularize the our social network site I have checked some of social network sites at that time we got idea to implement import contacts concept is best to intimate all of our friends at a time I have searched so many websites to implement this concepts but no result finally I have implemented import contacts from gmail 

I used ASP.NET and C# for developing this application.
We need to follow below steps to get gmail contacts 

Step-1:  Download Google data API setup from the specified URL 

Or you can directly download with the following

That Set Up will installs set of Google Data dll’s (Google.GData.Apps.dll, Google.GData.Client.dll, Google.GData.Contacts.dll, Google.GData.Extensions.dll) into client installed Machine, you should collect that dll’s for your program.

Step-2:  Design our aspx page (Default.aspx) by using with the following UI as simple scenario.

<html xmlns="">
<head runat="server">
<title>IMport Gmail Contacts</title>
<form id="form1" runat="server">
<asp:TextBox ID="txtgmailusername" runat="server"></asp:TextBox>
<asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:GridView ID="gvmails" runat="server"></asp:GridView>
Step-3:  Add those downloaded google dll’s as reference to your website in visual studio->Solution Explorer ->Right Click-> Click on Add Reference….->Browse ->Get dll’s from Installed Location->Press OK.

A) Add namespace these namespace to your code behind

using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.Contacts;
B) After that write following code in code behind

public static DataSet GetGmailContacts(string App_Name, string Uname, string UPassword)
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataColumn C2 = new DataColumn();
C2.DataType = Type.GetType("System.String");
C2.ColumnName = "EmailID";
RequestSettings rs = new RequestSettings(App_Name, 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();
return ds;
protected void Button1_Click(object sender, EventArgs e)
DataSet ds = GetGmailContacts("MyNetwork Web Application!", txtgmailusername.Text, txtpassword.Text);
gvmails.DataSource = ds;

Note:Keep Remember You Need Internet Connection @ the Time of Executing This Application.
I hope it helps you 

Download sample code attached
Protected by Copyscape Unique Content Checker

Categories: ASP.NET, C#

Post a Comment


Oops, you forgot something.


The words you entered did not match the given text. Please try again.

You must be a member to comment on this page. Sign In or Register