Powered by Blogger.

Saturday, July 17, 2010

Import Gmail Contacts into ASP.NET GridView

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.

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

Download


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

No comments:

Post a Comment

  ©Template by Dicas Blogger.

TOPO