.net - Import Address Book from Gmail/Hotmail/Yahoo using C# and ASP.NET

In this page, you will find, how to import contacts from Gmail with the help of Google data API which Google has provided us to import Gmail contacts, and also different .NET Address Book API's to import contacts from Gmail, Yahoo, MSN. Please find the sample code in ASP.Net ( C# language )


Please find below sample ASP.Net code to import contacts from Gmail.

using Google.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Contacts;

Contacts.aspx
<div>
    <table>
        <tr>
            <td>
                <asp:Label ID="lblEmail" runat="server" Text="Email:">asp:Label>
            td>
            <td>
                <asp:TextBox ID="txtEmail" runat="server">asp:TextBox>
            td>
        tr>
        <tr>
             <td>
                <asp:Label ID="lblPassword" runat="server" Text="Password:">asp:Label>
            td>
            <td>
                <asp:TextBox ID="txtPwd" runat="server" TextMode="Password">asp:TextBox>
            td>
        tr>
        <tr>
            <td colspan="2">
                <asp:Button ID="btnImportContacts" runat="server" Text="Import Contacts"
                    onclick="btnImportContacts_Click" />
            td>        
        tr>
        <tr>
            <td colspan="2">
                <asp:GridView ID="grdContacts" runat="server" AutoGenerateColumns="false">
                    <Columns>
                        <asp:BoundField DataField="Title" HeaderText="Title" />
                        <asp:BoundField DataField="EmailID" HeaderText="EmailID" />
                    Columns>
                asp:GridView>
            td>                
        tr>
    table>
div>

Contacts.aspx.cs

public class Contacts
{
    private string _EmailID;
    private string _Title;
 
    public string EmailID
    {
       get
       {
            return _EmailID;
        }
 
        set
        {
            _EmailID = value;
        }
    }
 
    public string Title
    {
        get
        {
            return _Title;
        }
 
        set
        {
            _Title = value;
        }
    }
}



protected void btnImportContacts_Click(object sender, EventArgs e)
{
      RequestSettings reqSettings = new RequestSettings("HimasagarContacts", txtEmail.Text, txtPwd.Text);
      reqSettings.AutoPaging = true;
 
      ContactsRequest contReq = new ContactsRequest(reqSettings);
      Feed<Contact> Contacts = contReq.GetContacts();
 
      List<GmailContacts> objContacts = new List<GmailContacts>();
       
      foreach (Contact objContact in Contacts.Entries)
      {
            GmailContacts objGmailContacts = new GmailContacts();
            objGmailContacts.Title = objContact.Title.ToString();
 
            foreach (EMail emailId in objContact.Emails)
            {
                 objGmailContacts.EmailID = emailId.Address.ToString() + ",";
            }
            if (objGmailContacts.EmailID != null)
            {
                 objGmailContacts.EmailID = objGmailContacts.EmailID.Substring(0, objGmailContacts.EmailID.Length - 1);
            }
            objContacts.Add(objGmailContacts);
     }
 
     grdContacts.DataSource = objContacts;
     grdContacts.DataBind();
}



What is GST

GST (Goods and Service Tax) is a comprehensive tax on the supply of goods and services at each stage of any transaction. Read More

Income Tax Information

An income tax is a tax imposed by government on income earned by you. Income tax is a key source of funds that the government uses to fund its activities and serve the public. Read More

General Insurance Companies in India

General insurance is insurance for valuables other than our life and health. General insurance covers the insurer against damage, loss and theft of your valuables. Read More



Types of Bank Loans In India

Loan means lending money from one individual or entity to another. A loan has three components – principal or the borrowed amount, rate of interest and tenure or duration for which the loan is availed. Read More

List of Banks in India

The Reserve Bank of India is the central Bank that is fully owned by the Government of India. It is governed by a central board (headed by a Governor) appointed by the Central Government. Read More

List of Educational Institutions in India

The following list of comprehensive websites on higher education in India. These websites will provide detailed information on education system in India. Read More