共用方式為


修改電子名片的版面配置

此範例示範如何使用 ContactItem 介面的 BusinessCardLayoutXml 屬性來修改電子名片的版面配置。

範例

注意事項

下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。

電子名片提供可從該聯繫人擷取特定資訊的聯繫人檢視。 ContactItem 介面提供與電子名片相關的特定成員。 這些成員包括 BusinessCardLayoutXmlBusinessCardTypeAddBusinessCardLogoPicture (String) ForwardAsBusinessCard () ResetBusinessCard () SaveBusinessCardImage (String) ShowBusinessCardEditor ()

在下列程式代碼範例中,BusinessCardLayoutExample 會先取得指定的 ContactItem 物件,以修改電子名片的版面配置。 在此情況下, ContactItem 是一個聯繫人, 其 Subject 屬性的值等於 「在 MacBeth」。 接下來,BusinessCardLayoutExample 會建立 XML 檔類別 XmlDocument,然後使用 ContactItem 物件的 BusinessCardLayoutXML 值,在字元串中取得這個類別的配置屬性。 卡片版面配置接著會從靠左對齊變更為靠右對齊。

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();
        }
    }
}

另請參閱