Modify the layout of an electronic business card
This example shows how to modify the layout of an electronic business card by using the BusinessCardLayoutXml property of the ContactItem interface.
Example
Note
The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007.
An electronic business card provides a contact view that captures specific information from that contact. The ContactItem interface provides specific members that pertain to electronic business cards. These members are BusinessCardLayoutXml, BusinessCardType, AddBusinessCardLogoPicture(String), ForwardAsBusinessCard(), ResetBusinessCard(), SaveBusinessCardImage(String), and ShowBusinessCardEditor().
In the following code example, BusinessCardLayoutExample modifies the layout of an electronic business card by first obtaining a specified ContactItem object. In this case, the ContactItem is a contact with the value of the Subject property equal to “Melissa MacBeth”. Next, BusinessCardLayoutExample creates an XML document class XmlDocument, and then gets the layout attribute of this class in a string by using the BusinessCardLayoutXML value for the ContactItem object. The card layout is then changed from left-aligned to right-aligned.
If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.
using Outlook = Microsoft.Office.Interop.Outlook;
private void BusinessCardLayoutExample()
{
Outlook.ContactItem contact =
Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderContacts).Items.Find(
"[Subject] = Melissa MacBeth'")
as Outlook.ContactItem;
if (contact != null)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(contact.BusinessCardLayoutXml);
XmlElement root = doc.DocumentElement;
string layoutValue = root.GetAttribute("layout");
if (layoutValue == "left")
{
root.SetAttribute("layout", "right");
contact.BusinessCardLayoutXml = doc.OuterXml;
contact.Save();
}
}
}