我想通过Mapi从Outllok导入联系人。 标准联系的第一步没有问题:
MAPIFolder contactObjects =
outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
foreach (ContactItem contactObject in contactObjects.Items) {
... import contact ...
}
在第二步中,我还想要导入共享联系人。我发现只有使用
OpenSharedItem(sharedContacts.vcf)
但我不知道我要打开的文件(共享项)的名称。 有人知道如何访问共享联系人并可以帮助我吗?
托比
更新:
感谢vcf-Files的提示。但是我在哪里可以找到它们?
UPDATE2:
我玩过OutlookSpy。我可以访问具有共享联系人的文件夹,但只能通过知道ID(当然对其他用户不同):
var ns = outlookObj.GetNamespace("MAPI");
var flr = ns.GetFolderFromID("00000000176A90DED92CE6439C1CB89AFE3668F90100D1AD8F66B576B54FB731302D9BB9F6C40007E4BAC5020000");
foreach (var contactObject in flr.Items) {
...
}
如何在不知道ID的情况下访问该文件夹?
答案 0 :(得分:2)
您需要显式解析vCard文件,或者您可以使用Redemption - 它允许使用RDOContactItem导入vCard文件。导入 - http://www.dimastr.com/redemption/RDOMail.htm#methods
答案 1 :(得分:1)
在标题中提到问题的解决方案几乎是简单的。 你只需要打电话:
Recipient recip = Application.Session.CreateRecipient("Firstname Lastname");
MAPIFolder sharedContactFolder = Application.Session.GetSharedDefaultFolder(recip, OlDefaultFolders.olFolderContacts);
因为这不能解决我的问题,我会问another question!
答案 2 :(得分:0)
我做了一些编程来接触outlook。 我正在给你一些示例代码来帮助你解决这个问题。它并不是很想要你想要但我认为这会帮助你解决问题......
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;
}
答案 3 :(得分:0)
var outlook = new Microsoft.Office.Interop.Outlook.Application();
NameSpace mapiNamespace = outlook.Application.GetNamespace("MAPI");
foreach (Store store in mapiNamespace.Stores)
{
try
{
var folder = store.GetRootFolder();
foreach(MAPIFolder subfolder in folder.Folders)
{
if ( subfolder.Name == "Inbox")
{
foreach(dynamic message in subfolder.Items.Restrict("[MessageClass]='IPM.Sharing'"))
{
if (message.Class == 104)//SharingItem
{
Folder sharedFolder = message.OpenSharedFolder();
if (sharedFolder.DefaultMessageClass == "IPM.Contact")
{
//this is your folder
}
}
}
}
}
}
catch (System.Exception ex)
{
continue;
}
}