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

Wednesday, June 15, 2005

bonus res adeo qui exspecto

BCM Update (AKA 2.0)

Tuesday, June 14, 2005

How to run SQL against the BCM database

OSQL is installed with SQLServer.

On the same machine as BCM, with the same login that installed BCM, from a command prompt, run:

OSQL -E -S .\microsoftsmlbiz -d msbusinesscontactmanager

Use your own server instance and database names if they are different from the defaults.

You find can your server instance name by looking at your SQL Server service; Start, My Computers, Manage, Services and Applications\Services.

You can find database name in your mail profile; Start, Control Panel, Mail, Show Profiles, select your bcm profile, Properties, Data Files..., Name: Business Contact Manager, Filename: :

From the OSQL prompt you can enter SQL commands; e.g. SELECT * FROM OrgTable
Type GO on the following line to execute the command.
Type EXIT to leave OSQL.

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)
{
}
}
}
}
}

Connect.cs

namespace SyncContacts
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Windows.Forms;

// Based on http://support.microsoft.com/?kbid=302901

[GuidAttribute("06279257-8C10-4581-B307-2D537484DB18"), ProgId("SyncContacts.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
private CommandBarButton SyncButton;

public Connect()
{
}

public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
applicationObject = application;
addInInstance = addInInst;

if(connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
}

public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
{
if(disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
applicationObject = null;
}

public void OnAddInsUpdate(ref System.Array custom)
{
}

public void OnStartupComplete(ref System.Array custom)
{
CommandBars oCommandBars;
CommandBar oStandardBar;

try
{
oCommandBars = (CommandBars)applicationObject.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty , null, applicationObject ,null);
}
catch(Exception)
{
object oActiveExplorer;
oActiveExplorer= applicationObject.GetType().InvokeMember("ActiveExplorer",BindingFlags.GetProperty,null,applicationObject,null);
oCommandBars= (CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars",BindingFlags.GetProperty,null,oActiveExplorer,null);
}

oStandardBar = oCommandBars["Standard"];

try
{
SyncButton = (CommandBarButton)oStandardBar.Controls["Sync Contacts"];
}
catch(Exception)
{
object omissing = System.Reflection.Missing.Value ;
SyncButton = (CommandBarButton) oStandardBar.Controls.Add(1, omissing , omissing , omissing , omissing);
SyncButton.Caption = "Sync Contacts";
SyncButton.Style = MsoButtonStyle.msoButtonCaption;
}

SyncButton.Tag = "Sync Contacts Button";
SyncButton.OnAction = "!";
SyncButton.Visible = true;
SyncButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.SyncButton_Click);

object oName = applicationObject.GetType().InvokeMember("Name",BindingFlags.GetProperty,null,applicationObject,null);

oStandardBar = null;
oCommandBars = null;
}

public void OnBeginShutdown(ref System.Array custom)
{
}

private void SyncButton_Click(CommandBarButton cmdBarbutton,ref bool cancel)
{
Cursor.Current = Cursors.WaitCursor;
SyncContacts sc = new SyncContacts();
try
{
sc.CopyOrUpdateOutlookContactsToBcm(applicationObject);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "SyncContacts");
}
Cursor.Current = Cursors.Default;
}

private object applicationObject;
private object addInInstance;
}
}

Add-in to copy Contacts to Business Contacts

As an experiment I wrote an Outlook Add-in that copies or updates Contacts from the Outlook Contacts folder to the BCM Business Contacts folder.

Extending it to do the reverse, or both, should be a straightforward exercise.

I'll post the relevant code in the next couple of entries.

Basically I started with an example Add-in from the Microsoft Knowledge base, added the BCM specific code, and removed some unnecessary code.

If anyone's interested I can zip and post the binaries with the generated setup program--it sets the add-in values in the Registry for Outlook.