我正在编写一个程序,我需要从我的Outlook中获取我的共享联系人列表。我写了一个代码,它返回了我的联系人列表(不是共享的)。 我怎样才能获得共享联系人?
这是我的代码:
Private Sub GetListOfContacts(cmb As ComboBox)
Dim OutlookApp As Outlook.Application = New Outlook.Application()
Dim contactItemsList As List(Of Outlook.ContactItem) = Nothing
Dim folderItems As Outlook.Items = Nothing
Dim folderSuggestedContacts As Outlook.MAPIFolder = Nothing
Dim ns As Outlook.NameSpace = Nothing
Dim folderContacts As Outlook.MAPIFolder = Nothing
Dim itemObj As Object = Nothing
Dim contact As Outlook.ContactItem
Try
contactItemsList = New List(Of Outlook.ContactItem)()
ns = OutlookApp.GetNamespace("MAPI")
'getting items from the Contacts folder in Outlook
folderContacts = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
folderItems = folderContacts.Items
For i As Integer = 1 To folderItems.Count
itemObj = folderItems(i)
If (TypeOf (itemObj) Is Outlook.ContactItem) Then
contact = itemObj
cmb.Items.Add(contact.FullName)
Else
Marshal.ReleaseComObject(itemObj)
End If
Next
Catch ex As Exception
谢谢!
答案 0 :(得分:1)
Use Namespace.GetSharedDefaultFolder
and pass the Recipient object retrieved from Namespace.CreateRecipient
.
Dim recip as Outlook.Recipient
...
recip = ns.CreateRecipient("SomeExchangeUserName")
folderContacts = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderContacts)