共用方式為


建立通訊組清單

此範例示範如何建立通訊組清單,並顯示給使用者。

範例

注意事項

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

在下列程式代碼範例中,CreateDistributionList 會藉由呼叫 CreateItem (OlItemType) 方法來建立 DistListItem 物件來建立通訊組清單。 接下來,它會建立 Table 物件,並呼叫 GetTable (Object, Object) 方法,以尋找 Default Contacts 資料夾中 Subject 屬性值 為 “Top Customer” 且 Email1Address 屬性值不是空的所有聯繫人。 識別所有聯繫人之後, Email1Address 名稱就會新增為數據 表的數據行。 CreateDistributionList 接著會使用來自 NameSpace物件的CreateRecipient (String) 方法來建立 Recipient 物件。 CreateDistributionList 最後會向用戶顯示「熱門客戶」通訊組清單。

注意事項

您必須將解析的 Recipient 物件當做參數傳遞至 DistListItem 物件的 AddMember (Recipient) 方法。 若要解析 Recipient 物件,請使用 Resolve () 方法。

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 CreateDistributionList()
{
    Outlook.DistListItem distList = Application.CreateItem(
        Outlook.OlItemType.olDistributionListItem)
        as Outlook.DistListItem;
    distList.Subject = "Top Customers";
    //Find top customer category in Contacts folder
    string filter = "[Categories] = 'Top Customer'"
        + " AND [Email1Address] <> ''";
    Outlook.Table table =
        Application.Session.GetDefaultFolder
        (Outlook.OlDefaultFolders.olFolderContacts).
        GetTable(filter, Outlook.OlTableContents.olUserItems);
    table.Columns.Add("Email1Address");
    while (!table.EndOfTable)
    {
        Outlook.Row nextRow = table.GetNextRow();
        Outlook.Recipient recip =
            Application.Session.CreateRecipient(
            nextRow["Email1Address"].ToString());
        //Resolve the Recipient before calling AddMember
        recip.Resolve();
        distList.AddMember(recip);
    }
    distList.Display(false);
}

另請參閱