简体   繁体   English

使用vb.net获取Outlook共享联系人列表

[英]Get a list of outlook shared contacts using vb.net

I'm writing a program and i need to get the list of my shared contacts from my outlook. 我正在编写一个程序,我需要从我的前景中获取共享的联系人列表。 I wrote a code that returns a list of my contacts (not the shared). 我编写了一个代码,返回了我的联系人列表(而不是共享列表)。 how can I get the shared contacts? 如何获得共享的联系人?

this is my code: 这是我的代码:

Private Sub GetListOfContacts(cmb As ComboBox) 私人子GetListOfContacts(cmb作为组合框)

    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 

Thanks! 谢谢!

Use Namespace.GetSharedDefaultFolder and pass the Recipient object retrieved from Namespace.CreateRecipient . 使用Namespace.GetSharedDefaultFolder并传递从Namespace.CreateRecipient检索到的Recipient对象。

Dim recip as Outlook.Recipient
...
recip = ns.CreateRecipient("SomeExchangeUserName")
folderContacts = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderContacts)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM