2012-11-02 83 views
8

我想通過Mapi從Outllok導入聯繫人。 與標準接觸第一步是沒有問題:Outlook Mapi訪問共享聯繫人

MAPIFolder contactObjects = 
outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts); 
foreach (ContactItem contactObject in contactObjects.Items) { 
    ... import contact ... 
} 

在第二步驟中我另外要導入共享聯繫人。只有我發現的東西是用

OpenSharedItem(sharedContacts.vcf) 

,但我不知道該文件(共享項目)的名稱,我想開。 有人知道如何訪問共享聯繫人,並可以幫助我嗎?

託比


更新:

感謝您與VCF檔案的提示。但我在哪裏找到他們?


UPDATE2:

我OutlookSpy發揮各地。我得到了與共享的聯繫人文件夾訪問權限,但只能通過知道ID(這當然是不同的其他用戶):

var ns = outlookObj.GetNamespace("MAPI"); 
var flr = ns.GetFolderFromID("00000000176A90DED92CE6439C1CB89AFE3668F90100D1AD8F66B576B54FB731302D9BB9F6C40007E4BAC5020000"); 

foreach (var contactObject in flr.Items) { 
     ... 
} 

我如何獲得訪問該文件夾不知道ID?

回答

1

好解決了一個問題,它在標題中要求幾乎簡單。 你只需要調用:

Recipient recip = Application.Session.CreateRecipient("Firstname Lastname"); 
MAPIFolder sharedContactFolder = Application.Session.GetSharedDefaultFolder(recip, OlDefaultFolders.olFolderContacts); 

因爲這並沒有解決我的問題,我會問another question

0

我已經做了一些規劃,以獲得從Outlook聯繫人。 我給你一些示例代碼,以幫助您了這個..它是不是excatly想你想,但我認爲這將幫助你解決問題...

using System.Collections.Generic; 

// ... 

private List<Outlook.ContactItem> GetListOfContacts(Outlook._Application OutlookApp) 

    { 
    List<Outlook.ContactItem> contItemLst = null; 
    Outlook.Items folderItems =null; 
    Outlook.MAPIFolder mapiFoldSuggestedConts = null; 
    Outlook.NameSpace nameSpc = null; 
    Outlook.MAPIFolder mapiFoldrConts = null; 
    object itemObj = null; 

    try 
    { 

     contItemLst = new List<Outlook.ContactItem>(); 
     nameSpc = OutlookApp.GetNamespace("MAPI"); 
     // getting items from the Contacts folder in Outlook 
     mapiFoldrConts = 
      nameSpc.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); 

     folderItems = mapiFoldrConts.Items; 
     for (int i = 1; folderItems.Count >= i; i++) 
     { 

      itemObj = folderItems[i]; 
      if (itemObj is Outlook.ContactItem) 
       contItemLst.Add(itemObj as Outlook.ContactItem); 
      else 
       Marshal.ReleaseComObject(itemObj); 
     } 

     Marshal.ReleaseComObject(folderItems); 
     folderItems = null; 
     // getting items from the Suggested Contacts folder in Outlook 
     mapiFoldSuggestedConts = nameSpc.GetDefaultFolder( 

      Outlook.OlDefaultFolders.olFolderSuggestedContacts); 

     folderItems = mapiFoldSuggestedConts.Items; 

     for (int i = 1; folderItems.Count >= i; i++) 
     { 

      itemObj = folderItems[i]; 
      if (itemObj is Outlook.ContactItem) 
       contItemLst.Add(itemObj as Outlook.ContactItem); 

      else 
       Marshal.ReleaseComObject(itemObj); 
     } 
    } 

    catch (Exception ex) 
    { 
     System.Windows.Forms.MessageBox.Show(ex.Message); 
    } 

    finally 
    { 

     if (folderItems != null) 
      Marshal.ReleaseComObject(folderItems); 
     if (mapiFoldrConts != null) 
      Marshal.ReleaseComObject(mapiFoldrConts); 
     if (mapiFoldSuggestedConts != null) 
      Marshal.ReleaseComObject(mapiFoldSuggestedConts); 
     if (nameSpc != null) Marshal.ReleaseComObject(nameSpc); 
    } 

    return contItemLst; 

} 
+0

感謝您的代碼,但我已經這樣做了。導入標準或建議的聯繫人不是問題,而是閱讀共享聯繫人。 – Tobias