Roe*_*ler 4 c# wpf outlook contactitem
我正在开发一个需要对用户的Outlook联系人执行某些处理的应用程序.我正在通过迭代结果来访问Outlook联系人列表MAPIFolder.Items.Restrict(somefilter),可以在其中找到Microsoft.Office.Interop.Outlook.
在我的应用程序中,我的用户需要选择几个联系人来应用某个操作.我想添加一个功能,允许用户从Outlook拖动联系人并将其放在UI中的某个ListBox上(我在WPF中工作,但这可能是更通用的问题).
我是C#和WPF的新手 - 我怎么能:
谢谢
我尝试使用TextBox(在实践中与ListBox没有区别).
摘要:
在所有Outlook联系人中搜索被收录的文本.此处的搜索基于此人的FullName.
条件):
拖动联系人时,它必须在Outlook中选中时显示FullName.唯一的问题是当两个人拥有相同的全名!! 如果是这种情况,您可以尝试通过组合ContactItem属性并在拖动的文本中搜索它们来为人找到唯一标识符.
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetData("Text") != null)
{
ApplicationClass app;
MAPIFolder mapif;
string contactStr;
contactStr = e.Data.GetData("Text").ToString();
app = new ApplicationClass();
mapif = app.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderContacts);
foreach (ContactItem tci in mapif.Items)
{
if (contactStr.Contains(tci.FullName))
{
draggedContact = tci; //draggedContact is a global variable for example or a property...
break;
}
}
mapif = null;
app.Quit;
app = null;
GC.Collect();
}
}
Run Code Online (Sandbox Code Playgroud)
当然这个代码是有组织优化的,它只是解释使用的方法.
您可以尝试将Explorer.Selection属性与GetData("Text")结合使用[以确保它来自Outlook,或者您可以在DragOver事件中使用GetData("Object Descriptor"),解码内存流,搜索"outlook" ",如果没有找到取消拖动操作]为什么不拖动多个联系人!
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetData("Text") != null)
{
ApplicationClass app;
Explorer exp;
List<ContactItem> draggedContacts;
string contactStr;
contactStr = e.Data.GetData("Text").ToString();
draggedContacts = new List<ContactItem>();
app = new ApplicationClass();
exp = app.ActiveExplorer();
if (exp.CurrentFolder.DefaultItemType == OlItemType.olContactItem)
{
if (exp.Selection != null)
{
foreach (ContactItem ci in exp.Selection)
{
if (contactStr.Contains(ci.FullName))
{
draggedContacts.Add(ci);
}
}
}
}
app = null;
GC.Collect();
}
}
Run Code Online (Sandbox Code Playgroud)