Get Gmail Contact for C#
Frist : Click here to download this dll and install it.
Second:
<%@ 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>Untitled
Page</title>
</head>
<body>
<form id="form1" runat="server">
Email Address<asp:TextBox ID="email" runat="server"></asp:TextBox><br />
Password<asp:TextBox ID="password" runat="server"></asp:TextBox><br />
<asp:Button ID="Get" runat="server" OnClick="GetOnclick" Text="GO" />
<div>
<asp:gridview ID="Gridview1" runat="server"></asp:gridview>
</div>
</form>
</body>
</html>
Third:
Add reference to installed dll file
Forth:
using System;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Xml.Linq;
using
Google.GData.Client;
using
Google.Contacts;
using
Google.GData.Extensions;
using
System.Collections.Generic;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
public void GetOnclick(object
sender, EventArgs e)
{
FetchContactList(email.Text,
password.Text);
}
private void FetchContactList(string
email, string pwd)
{
List<string> lstContacts = new
List<string>();
// Here
required your gmail id and password.
RequestSettings
rsLoginInfo = new RequestSettings("", email, pwd);
rsLoginInfo.AutoPaging = true;
ContactsRequest
cRequest = new ContactsRequest(rsLoginInfo);
// fetch
contacts list
Feed<Contact> feedContacts = cRequest.GetContacts();
// looping
the feedcontact entries
foreach
(Contact gmailAddresses in feedContacts.Entries)
{
//
Looping to read email addresses
foreach
(EMail emailId in
gmailAddresses.Emails)
{
lstContacts.Add(emailId.Address);
}
}
// finally
binding the list to gridview defined in above step
Gridview1.DataSource = lstContacts;
Gridview1.DataBind();
}
}
Manish Siddhapara ||
+91-97258 78998