That's on the right track but needs some refinement. You must to declare an explicit Items object at the class level, instantiate it in your procedure, and then create the event handler. The Items object must be a class-level object in order to persist so that it can fire events.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
"Aidal" wrote in message ...
Sue Mosher [MVP-Outlook] skrev:
1) Do somthing when ever a ContactItem (or Account) is created.
Subscribe to the MAPIFolder.Items.ItemAdd event for the desired folder(s). The sample at http://www.outlookcode.com/codedetail.aspx?id=456 is for the Sent Items folder, but it can supplement the information on that event in Help.
2) Do somthing when ever a ContactItem (or Account) is edited.
MAPIFolder.Items.ItemChange event. Another sample to supplement what's in Help: http://www.outlookcode.com/codedetail.aspx?id=566
3) Do somthing when ever a ContactItem (or Account) is deleted.
There's no surefire way to catch that until Outlook 2007. ContactItem.BeforeDelete fires only if the user has the item open and MAPIFolder.Items.ItemRemove doesn't return the item that was removed. One approach is to maintain your own list of what items are in each folder and check it against the actual folder contents whenever ItemRemove fires.
Ok, I've checked out your example. I'm not sure I've translated your
code correctly to C# though.
I've created my own little class to test and am trying to use it from a
console application.
-----------------------------------
// available within the class
Outlook.ApplicationClass olAppClass;
Outlook.NameSpace olNameSpace;
Outlook.Folders olFolders;
Outlook.MAPIFolder olBcmRootFolder;
// Within my class constructor
olAppClass = new Outlook.ApplicationClass();
olNameSpace = olAppClass.GetNamespace("MAPI");
olFolders = olNameSpace.Session.Folders;
olBcmRootFolder = olFolders["Business Contact Manager"];
olBcmRootFolder.Folders["Accounts"].Items.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(InstanceAd ded_Account);
// No longer within constructor
public void InstanceAdded_Account(object item)
{
Console.WriteLine("account created: " +
((Outlook.ContactItem)item).FullName);
}
-----------------------------------
This should give me some console output when an Account is created or am
I missing somthing here?
Does the delegate have to have a certain name in order for it to work maybe?
/Aidal