.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Import Gmail Contacts into ASP.NET GridView

Posted By:BangaruBabuPureti       Posted Date: April 19, 2010    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  

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

Abstract:In this article I will explain how to import gmail contacts of a user by using GContacts Data API provided by Google. This Article will help the developers, who are willing to develop SOCIAL NETWORK applications like facebok, orkut, hi5, twitter e.t.c.In Social Network Applications -their objective is to promote their website world wide to n-no of users, for that they targets gmail,yahoomail,AOL,hotmail e.t.c.where you need to invite more people. By keeping that motive in mind I prepared this article with help of Google Contacts API and their suggested source code, I customized according to my Requirement. Its Just like kids play. There is no need to think more and more with Hazards of knowledge.I will explain this article with Step by Step.

Hands on Experiment:I used ASP.NET and C# for developing this application. Let Me Explain This Article Step By Step without talking much more introduction. This Article Targets Intermediate Developers who are having minimal knowledge on ASP.NET and C#.


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.

 Step2:Design one page (Default.aspx) by using with the following UI as simple scenario.

Step-3:Add one New Class file to App_Code Folder->Now add that dll's(Google.GData.Apps.dll, Google.GData.Client.dll, Google.GData.Contacts.dll, and Google.GData.Extensions.dll) as a reference to your website by using a good option in visual studio->Solution Explorer ->Right Click-> Click on Add Reference..->Browse ->Get dll's from Installed Location->Press OK.


a) Import Name spaces.

using Google.GData.Contacts;

using Google.GData.Client;

using Google.GData.Extensions;

using Google.Contacts;

b) Write Function As

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 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;



a) open default.aspx->under button_Click(Get Contacts)  U need to Write The Code as follows

 Session["username"] = txtgmailusername.Text;

 Session["password"] = txtpassword.Text;

 Session["App_Name"] = "MyNetwork Web Application!";


b)Add One New Page Named (PopulateGcontacts.aspx).Place One GridVie Control and write the code as follows.

protected void Page_Load(object sender, EventArgs e)

    string App_Name = Session["App_Name"].ToString();

    string username = Session["username"].ToString();

    string password = Session["password"].ToString();

    DataSet ds = GContactsImport.GetGmailContacts(App_Name, username, password);

    GridView1.DataSource = ds;



protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    GridView1.PageIndex = e.NewPageIndex;

      Finally our Output Screen Will Be Like This

My Resource:


Note:Keep Remember You Need Internet Connection @ the Time of Executing This Application.

Soon I Will Post hotmail,yahoomail,AOL Contacts Import into asp.net application as a Group.


In this example I left to catch exceptions and validations.This article will definitly help in to make the above mentioned scenario in real development.For This Work I made lot of gogle Search But I Never Get Any Exact Solution to solve My Requirement In Easy Manner.Finally I Solved It with GContacts DataApi. Soon I Will Post hotmail,yahoomail,AOL Contacts Import into asp.net application as a Group.

Feed Back Always Expected-----Comment Or Post Ur Issues Below

 Subscribe to Articles


Further Readings:

Author: patrick         Company URL: http://www.dotnetspark.com
Posted Date: August 10, 2010

you can use this component with .Net, c# and VB.. http://www.socialcontactsimporter.net Worked on our web site like a dream and works with all the major providers, Hotmail, Gmail, Yahoo, Outlook, Outlook Express, Firefox and so on..

We tried a number of ways even creating our own but was no good because the email providers (hotmail etc,) kept on changing their web sites making our code break.. Dont waist your time. Life is too short.

They also do hourly testing to make sure it works.

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend