共用方式為


顯示設定檔的通訊清單

此範例示範如何顯示目前配置檔的通訊清單。

範例

注意事項

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

目前的配置檔包含 AddressLists 集合所代表的通訊清單。 若要取得 AddressLists 集合的實例,您必須使用 NameSpace 物件的 AddressLists 屬性。

在下列程式代碼範例中,EnumerateAddressLists 會先使用 foreach 語句列舉 AddressLists 集合中的每個 AddressList 物件。 然後,此範例會建立一個字串,其中包含 NameResolutionOrderIsReadOnlyIsInitialAddressList 屬性的值。 最後,EnumerateAddressLists 會將字串寫入接聽程式集合的追蹤接 程式。 這會顯示目前配置檔的每個通訊清單。

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 EnumerateAddressLists()
{
    Outlook.AddressLists addrLists =
         Application.Session.AddressLists;
    foreach (Outlook.AddressList addrList in addrLists)
    {
        StringBuilder sb = new StringBuilder();
        sb.AppendLine("Display Name: " + addrList.Name);
        sb.AppendLine("Resolution Order: "
            + addrList.ResolutionOrder.ToString());
        sb.AppendLine("Read-only : "
            + addrList.IsReadOnly.ToString());
        sb.AppendLine("Initial Address List: "
            + addrList.IsInitialAddressList.ToString());
        sb.AppendLine("");
        Debug.WriteLine(sb.ToString());
    }
}

另請參閱