Mitdasein in the experience of encountering the customer in our common having been cast into the opening of beyng

Wednesday, June 08, 2005

SyncContacts.cs

using System;
using Microsoft.Office.Interop.Outlook;

namespace SyncContacts
{
///
/// Summary description for SyncContacts.
///

public class SyncContacts
{
public SyncContacts()
{
}

void UpdateProperties(ContactItem ci, ContactItem newContact)
{
foreach (ItemProperty ip in ci.ItemProperties)
{
try
{
newContact.ItemProperties[ip.Name].Value = ip.Value;
}
catch (System.Exception)
{
// bunch of properties are read-only
}
}
}

internal void CopyOutlookContactsToBcm(object app)
{
NameSpace ns = ((Application)app).GetNamespace("MAPI");
Folders messageStores = ns.Session.Folders;
MAPIFolder bcmFolder = messageStores["Business Contact Manager"];
MAPIFolder bcmContactsFolder = bcmFolder.Folders["Business Contacts"];
MAPIFolder olContactsFolder = ns.GetDefaultFolder(OlDefaultFolders.olFolderContacts);

foreach (ContactItem ci in olContactsFolder.Items)
{
ContactItem newContact = (ContactItem)bcmContactsFolder.Items.Add("IPM.Contact.Iris.Contact");
UpdateProperties(ci, newContact);
newContact.Save();
}
}

internal void CopyOrUpdateOutlookContactsToBcm(object app)
{
NameSpace ns = ((Application)app).GetNamespace("MAPI");
Folders messageStores = ns.Session.Folders;
MAPIFolder bcmFolder = messageStores["Business Contact Manager"];
MAPIFolder bcmContactsFolder = bcmFolder.Folders["Business Contacts"];
MAPIFolder olContactsFolder = ns.GetDefaultFolder(OlDefaultFolders.olFolderContacts);

foreach (ContactItem ci in olContactsFolder.Items)
{
string findstr = "[FileAs] = \"" + ci.FileAs + "\"";
ContactItem bcmContact = null;
try
{
bcmContact = (ContactItem)bcmContactsFolder.Items.Find(findstr);
}
catch (System.Exception)
{
}

if (bcmContact == null)
{
bcmContact = (ContactItem)bcmContactsFolder.Items.Add("IPM.Contact.Iris.Contact");
}
UpdateProperties(ci, bcmContact);
try
{
bcmContact.Save();
}
catch (System.Runtime.InteropServices.COMException)
{
}
}
}
}
}

0 Comments:

Post a Comment

<< Home