Import Gmail Contacts into ASP.NET GridView

BangaruBabu
Posted by in ASP.NET category on for Beginner level | Views : 39747 red flag
Rating: 4.64 out of 5  
 11 vote(s)

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.


 Download source code for Import Gmail Contacts into ASP.NET GridView

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#.

Step1:

Download Google data API setup from the specified URL

http://code.google.com/p/google-gdata/

Or you can directly download with the following

http://google-gdata.googlecode.com/files/Google%20Data%20API%20Setup%281.4.0.2%29.msi

 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.

 Step-4:

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";      
dt.Columns.Add(C2);
       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();
              
dt.Rows.Add(dr1);
           
}
       
}
ds.Tables.Add(dt);
return ds;

}

Step-5:

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

Response.Redirect("~/PopulateGcontacts.aspx");

b)Add One New Page Named (PopulateGcontacts.aspx).Place One GridView 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;

GridView1.DataBind();

}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

GridView1.PageIndex = e.NewPageIndex;

}


  Finally our Output Screen Will Be Like This

My Resource:

http://code.google.com/apis/contacts/docs/2.0/developers_guide_dotnet.html

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 definitely help in to make the above mentioned scenario in real development.For This Work I made lot of goggle 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

Page copy protected against web site content infringement by Copyscape

About the Author

BangaruBabu
Full Name: BangaruBabu Pureti
Member Level:
Member Status: Member
Member Since: 5/12/2010 2:15:06 AM
Country: India
BangaruBabu Pureti http://bangarubabupureti.spaces.live.com/
http://bangarubabupureti.spaces.live.com
Microsoft Technology Enthusiast

Login to vote for this post.

Comments or Responses

Posted by: ankitdadhich-4285 on: 6/24/2010
hi,excellent work.
thnx very much
Posted by: ankitdadhich-4285 on: 6/24/2010
very well explained thnk u very much,
u make it very simple.
i m waiting for importing contact from yahoo & aol.
thnks again,

ankit.dadhich@yahoo.com
Posted by: Mchilly on: 8/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.

Posted by: Akiii on: 6/19/2011 | Points: 25
Excellent work......
keep posting...

Thanks and Regards
Akiii

Login to post response

Comment using Facebook(Author doesn't get notification)