[Outlook]add contact item

M

Marcel Stör

Hi folks

Does anyone know how to add an object of type ContactItem to an _Items list?
_Items provides an add() method which, however, only accepts a Variant as
parameter... Here's what I do:
- logon to Exchange
- find default folder (public folder)
- navigate to the specific folder (contains contacts)
- as the MAPIFolder object for items -> _Items

and then?

Regards,
Marcel
 
S

Stefan

Hi Marcel
try
Outlook._ContactItem myContact = objMyContact as Outlook._ContactItem;
myContact.FirstName=firstname
....
myContact.Save()
 
M

Marcel Stör

Stefan said:
Hi Marcel
try
Outlook._ContactItem myContact = objMyContact as Outlook._ContactItem;
myContact.FirstName=firstname
...
myContact.Save()

According to the language reference this would save the contact item in its
default folder. However, the item doesn't need to be stored in the contacts
folder but rather in one specific public folder (the MAPIFolder object in my
pseudo code).


Regards,
Marcel
 
M

Marcel Stör

Marcel said:
Hi folks

Does anyone know how to add an object of type ContactItem to an
_Items list? _Items provides an add() method which, however, only
accepts a Variant as parameter... Here's what I do:
- logon to Exchange
- find default folder (public folder)
- navigate to the specific folder (contains contacts)
- as the MAPIFolder object for items -> _Items

and then?


Then I need to invoke move(MAPIFolder). That's all.

Regards,
Marcel
 
K

Karen Parker

Hi Marcel,

If you want to save a new Contact to a particular folder that is not the
default Contacts folder, then you should use the Add method of the Items
collection of that MAPIFolder. When the item is saved, you will not need
to perform the move method.

For example:
//The following example is a C# Console Application.
//You may need to make changes depending on the type of application you are
using.

static void Main(string[] args)
{
Outlook.Application objOL = new Outlook.ApplicationClass();
string str = objOL.Version;
Console.WriteLine(str);

//Get subfolder of Contacts called 'test'
Outlook.MAPIFolder objFolder =
objOL.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).Fo
lders["test"];

//Add a contact to this folder
Outlook.ContactItem objContact =
(Outlook.ContactItem)objFolder.Items.Add(Outlook.OlItemType.olContactItem);

objContact.FirstName = "First";
objContact.LastName = "Last";
objContact.Email1Address = "(e-mail address removed)";
objContact.Body = "This is a sample contact from C#";
objContact.Save();

Console.WriteLine("Contact was created!");

objContact = null;
objFolder = null;
objOL = null;
Console.ReadLine();
}


I hope the information that I provided here has been helpful to you.

Karen Parker
Microsoft, Developer Support Engineer - Windows Messaging / Outlook

Please do not send email directly to this alias. This alias is for
newsgroup purposes only.

Disclaimer: This posting is provided "AS IS" with no warranties, and
confers no rights.
--------------------
From: "Marcel Stör" <marcel at frightanic dot com>
Newsgroups: microsoft.public.dotnet.languages.csharp,microsoft.public.office.developer.a
utomation,microsoft.public.office.developer.com.add_ins
References: <[email protected]>
Subject: GOT IT (Re: [Outlook]add contact item)
Date: Fri, 12 Sep 2003 08:43:27 +0200
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Lines: 20
Message-ID: <[email protected]>
NNTP-Posting-Host: 80.238.139.246
X-Trace: 1063349007 read.news.ch.uu.net 239 80.238.139.246
X-Complaints-To: (e-mail address removed)
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!skynet.be!skynet.be!newsgate.cistron.nl!newsfeed.bit.nl!newsfeed.bit.nl
!newsfeed.kabelfoon.nl!195.129.110.21.MISMATCH!bnewsfeed00.bru.ops.eu.uu.net
!bnewsinpeer00.bru.ops.eu.uu.net!bnewspost00.bru.ops.eu.uu.net!emea.uu.net!r
ead.news.ch.uu.net!not-for-mail
Xref: cpmsftngxa06.phx.gbl microsoft.public.office.developer.automation:7338
microsoft.public.office.developer.com.add_ins:4509
microsoft.public.dotnet.languages.csharp:184301
X-Tomcat-NG: microsoft.public.office.developer.automation
Hi folks

Does anyone know how to add an object of type ContactItem to an
_Items list? _Items provides an add() method which, however, only
accepts a Variant as parameter... Here's what I do:
- logon to Exchange
- find default folder (public folder)
- navigate to the specific folder (contains contacts)
- as the MAPIFolder object for items -> _Items

and then?


Then I need to invoke move(MAPIFolder). That's all.

Regards,
Marcel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top