• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

How can I get outlook contact information?

I want to get all contct list of M$ outlook~
I need Name, PhoneNumber, E-mail, ...
Exactly, My app compatible with outlook import/export outlook contact list!

0
byungho
Asked:
byungho
  • 2
1 Solution
 
mikelittlewoodCommented:
Couple of previous PAQ's on the same subject came up with these answers. Maybe one will help you.

1) http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20508808.html

go to torry.net and in the quick search box type in "address book" and ull get the component called twindowsaddressbook, and a sample too, for delphi 5, it works on my d6, so it should work, and then u open the sample project, and play about with it, i had to play about with it, so it would extract all the contacts from the outlook address book


2) http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21437814.html

function TForm1.GetContactsFolder(fpath : string) : OLEVariant;
var
  outlook , objns, tfolder,last : OLEVariant;
  done : boolean;
  cpath : string;
begin
  outlook := CreateOLEObject('Outlook.Application');
  objNS:= Outlook.GetNamespace('MAPI');
  tfolder := objns.GetDefaultFolder('olContacts');
  result := tfolder;
  showmessage(tfolder.name);
end;

procedure TForm1.AddFolders(cfolder : OLEVariant ; tnode : TTreeNode);
var
  cfldr,last : OLEVariant;
  done : boolean;
  ttnode,cnode : TTreeNode;
  i : integer;
begin

  for i := 1 to cfolder.items.Count do
  begin
    cnode := trvwSendTo.Items.AddChild(tnode,cfolder.items(i).fullname);
    cnode.ImageIndex:=0;
    cnode.SelectedIndex:=0;
  end;
  if cfolder.folders.Count > 0 then
  begin
    done := false;
    last := cfolder.folders.getlast;
    cfldr := cfolder.folders.getfirst;
    repeat
      if cfldr.name=last.name then
        done:=true;
      ttnode:=trvwsendto.Items.AddChild(tnode,cfldr.name);
      ttnode.ImageIndex:=1;
      ttnode.SelectedIndex:=1;
      AddFolders(cfldr,ttnode);
      cfldr:=cfolder.folders.getnext;
    until done;
  end;
end;

Procedure TForm1.PopulateTreeView;
var
  outlook, NameSpace, Contacts: OleVariant;
  tnode : TTreenode;
begin
  TrvwSendTo.items.Clear;
  outlook := CreateOLEObject('Outlook.Application');
  NameSpace := outlook.GetNameSpace('MAPI');
  Contacts := NameSpace.GetDefaultFolder(olFolderContacts);
  tnode := trvwSendTo.items.addfirst(nil,'Contacts');
  tnode.ImageIndex:=1;
  tnode.SelectedIndex:=1;
  AddFolders(contacts,tnode);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  PopulateTreeView;
end;


3) http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21542066.html
0
 
byunghoAuthor Commented:
thank you ..

I want to find phone numbers(bussiness, home, office..)
0
 
bernaniCommented:

You can check the code I supplied here: http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21779984.html

with this code

(1 Button + 1 ListView on the Form):

implementation

{$R *.DFM}

uses comobj;

procedure TForm1.Button1Click(Sender: TObject);
const
  olFolderContacts = $0000000A;
var
  outlook, NameSpace, Contacts, Contact: OleVariant;
  i: Integer;
begin
  outlook := CreateOleObject('Outlook.Application');
  NameSpace := outlook.GetNameSpace('MAPI');

  Contacts := NameSpace.GetDefaultFolder(olFolderContacts);
  for i := 1 to Contacts.Items.Count do
  begin
   Contact := Contacts.Items.Item(i);
   {now you can read any property of contact. For example, full name and email address}

   ListView1.Items.Add.Caption := Contact.FullName + ' <' + Contact.Email1Address + '>';
   end;

  Outlook := UnAssigned;
end;

With this example, all you have to do is to add a line or replace the line

   ListView1.Items.Add.Caption := Contact.FullName + ' <' + Contact.Email1Address + '>';

and change the item Contact.Email1Address by one of those:

Birthday
Business2TelephoneNumber   <--- this one for example
BusinessAddress
BusinessAddressCity
BusinessAddressCountry
BusinessAddressPostalCode
BusinessAddressPostOfficeBox
BusinessAddressState
BusinessAddressStreet
BusinessFaxNumber  
BusinessHomePage
BusinessTelephoneNumber  <--- this one for example
CompanyAndFullName
CompanyMainTelephoneNumber     <--- this one for example
CompanyName
ComputerNetworkName
Department
Email1Address
Email1AddressType
Email1DisplayName
Email2Address
Email2AddressType
Email2DisplayName
Email3Address
Email3AddressType
Email3DisplayName
FirstName
FTPSite
FullName
FullNameAndCompany
GovernmentIDNumber
Hobby
Home2TelephoneNumber
HomeAddress
HomeAddressCity
HomeAddressCountry
HomeAddressPostalCode
HomeAddressPostOfficeBox
HomeAddressState
HomeAddressStree
HomeFaxNumber
HomeTelephoneNumber          <--- this one for example
Initials
ISDNNumber
JobTitle
Language
LastName
LastNameAndFirstName
MailingAddress
MailingAddressCity
MailingAddressCountry
MailingAddressPostalCode
MailingAddressPostOfficeBox
MailingAddressState
MailingAddressStreet
MiddleName
NickName
OfficeLocation
OrganizationalIDNumber
PersonalHomePage
PrimaryTelephoneNumber
Profession
Suffix
Title
WebPage

sth like

   ListView1.Items.Add.Caption := Contact.FullName + ' <' + Contact.Business2TelephoneNumber + '>';
   ListView1.Items.Add.Caption := Contact.FullName + ' <' + Contact.BusinessTelephoneNumber  + '>';
   ListView1.Items.Add.Caption := Contact.FullName + ' <' + Contact.CompanyMainTelephoneNumber + '>';

____________________________

Hope this help.
0
 
byunghoAuthor Commented:
Thank you
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now