HOW TO: List Members of a Distribution List by Using Outlook Object Model in Visual Basic .NET (313797)
The information in this article applies to:
- Microsoft Visual Basic .NET (2002)
- Microsoft Outlook 2002
- Microsoft .NET Framework SDK 1.0
This article was previously published under Q313797 SUMMARY This step-by-step article describes how to use Outlook 10.0
Object Library to list the members of a distribution list in Visual Basic
.NET.
back to the top
Create Sample to List the Members of a Distribution List Programmatically- Start Microsoft Visual Studio .NET.
- On the File menu, point to New, and then click Project.
- Click Visual Basic Projects under Project Types, and then click Console Application under Templates. By default, Module1.vb is created.
- Add a reference to the Microsoft Outlook 10.0 Object
Library. To do this, follow these steps:
- On the Project menu, click Add Reference.
- Click the COM tab.
- Click Microsoft Outlook 10.0 Object
Library, and then click Select
- Click OK. If you are prompted to generate wrappers for the library that
you selected, click Yes.
- In the Code window, replace the default code with the
following code:
Imports System.Reflection
Module Module1
Sub Main()
' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
' Get Mapi NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("YourValidProfile", Missing.Value, False, True) ' TODO:
' Get Global Address List.
Dim oDLs As Outlook.AddressLists = oNS.AddressLists
Dim oGal As Outlook.AddressList = oDLs.Item("Global Address List")
Console.WriteLine(oGal.Name)
' Get a specific distribution list.
' TODO: Replace the distribution list with a distribution list that is available to you.
Dim sDL As String = "TestDL"
Dim oEntries As Outlook.AddressEntries = oGal.AddressEntries
' No filter available to AddressEntries
Dim oDL As Outlook.AddressEntry = oEntries.Item(sDL)
Console.WriteLine(oDL.Name)
Console.WriteLine(oDL.Address)
Console.WriteLine(oDL.Manager)
' Get all of the members of the distribution list.
oEntries = oDL.Members
Dim oEntry As Outlook.AddressEntry
Dim i As Integer
For i = 1 To oEntries.Count
oEntry = oEntries.Item(i)
Console.WriteLine(oEntry.Name)
' Display the Details dialog box.
'oDL.Details(Missing.Value)
Next
' Log off.
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oDLs = Nothing
oGal = Nothing
oEntries = Nothing
oEntry = Nothing
End Sub
End Module
- Modify the code where you see the TODO comments.
- Press F5 to build and to run the application.
- Verify that the members of the distribution list are
displayed.
back to the top
REFERENCES For more information, visit the following Microsoft
Developer Network (MSDN) Web site:
back to the top
Modification Type: | Major | Last Reviewed: | 1/19/2006 |
---|
Keywords: | kbHOWTOmaster KB313797 kbAudDeveloper |
---|
|