拖放一个或多个邮件从Outlook到C#WPF应用程序 [英] Drag'n'drop one or more mails from Outlook to C# WPF application

查看:273
本文介绍了拖放一个或多个邮件从Outlook到C#WPF应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在.NET Framework Sp1上使用WPF编写的Windows客户端程序,其中需要的是客户端收到的电子邮件中的数据可以存储在数据库中。现在最简单的方法是使用ctrl-c / ctrl-v的关键词诱导量手动复制并粘贴文本,主题,联系信息和手动收集的时间。


$ b $我认为处理这个问题的一个简单方法是允许用户将一个或多个电子邮件从Outlook(它们全部使用Outlook 2007)拖入窗口,让我的应用程序提取必要的信息并发送它到后端系统存储。



然而,几个小时的谷歌搜索信息似乎表明这个看似基本的任务的令人震惊的缺乏信息。我会认为这样的东西在许多不同的设置中会很有用,但是到目前为止,我已经能够找到的一切都是半途而废的非解决方案。有没有人有任何建议,如何做到这一点?



由于我只是读邮件,没有发送任何东西或做任何事情,所以一个解决方案并不涉及憎恶的安全弹出窗口,但是任何事情都无法做到这一点,这是很好的。 / p>

基本上,如果我可以得到所有选择的邮件列表,从Outlook中拖放,我将能够自己处理其余的事件。 >

谢谢!



符文

解决方案

我发现一个很好的文章,应该完全符合你所需要的至。



更新



我能够获得该文章中的代码WPF有一点调整,以下是您需要做的更改。



将System.Windows.Forms.IDataObject的所有引用更改为System.Windows.IDataObject



在OutlookDataObject构造函数中,更改

  FieldInfo innerDataField = this.underlyingDataObject.GetType ().GetField(innerData,BindingFlags.NonPublic | BindingFlags.Instance); 

  FieldInfo innerDataField = this.underlyingDataObject.GetType()。GetField(_ innerData,BindingFlags.NonPublic | BindingFlags.Instance); 

将所有DataFormats.GetFormat调用更改为DataFormats.GetDataFormat



更改SetData实现

  public void SetData(string format,bool autoConvert,object data)
{
this.underlyingDataObject.SetData(format,autoConvert,data);
}

TO

  public void SetData(string format,object data,bool autoConvert)
{
this.underlyingDataObject.SetData(format,data,autoConvert);
}

通过这些更改,我可以将其保存到文件中正如文章所做的那样。对于格式化,但编号/项目符号列表对于代码片段不能正常工作。


I'm working on a windows client written in WPF with C# on .Net 3.5 Sp1, where a requirement is that data from emails received by clients can be stored in the database. Right now the easiest way to handle this is to copy and paste the text, subject, contact information and time received manually using an arthritis-inducing amount of ctrl-c/ctrl-v.

I thought that a simple way to handle this would be to allow the user to drag one or more emails from Outlook (they are all using Outlook 2007 currently) into the window, allowing my app to extract the necessary information and send it to the backend system for storage.

However, a few hours googling for information on this seem to indicate a shocking lack of information about this seemingly basic task. I would think that something like this would be useful in a lot of different settings, but all I've been able to find so far have been half-baked non-solutions.

Does anyone have any advice on how to do this? Since I am just going to read the mails and not send anything out or do anything evil, it would be nice with a solution that didn't involve the hated security pop ups, but anything beats not being able to do it at all.

Basically, if I could get a list of all the mail items that were selected, dragged and dropped from Outlook, I will be able to handle the rest myself!

Thanks!

Rune

解决方案

I found a great article that should do exactly what you need to.

UPDATE

I was able to get the code in that article working in WPF with a little tweaking, below are the changes you need to make.

Change all references from System.Windows.Forms.IDataObject to System.Windows.IDataObject

In the OutlookDataObject constructor, change

FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);

To

FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("_innerData", BindingFlags.NonPublic | BindingFlags.Instance);

Change all DataFormats.GetFormat calls to DataFormats.GetDataFormat

Change the SetData implementation from

public void SetData(string format, bool autoConvert, object data)
{
    this.underlyingDataObject.SetData(format, autoConvert, data);
}

TO

public void SetData(string format, object data, bool autoConvert)
{
    this.underlyingDataObject.SetData(format, data, autoConvert);
}

With those changes, I was able to get it to save the messages to files as the article did. Sorry for the formatting, but numbered/bulleted lists don't work well with code snippets.

这篇关于拖放一个或多个邮件从Outlook到C#WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆