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