問題描述
我正在開發(fā)一個在 .Net 3.5 Sp1 上使用 C# 用 WPF 編寫的 Windows 客戶端,其要求是客戶端收到的電子郵件中的數(shù)據(jù)可以存儲在數(shù)據(jù)庫中.現(xiàn)在最簡單的處理方法是復制和粘貼文本、主題、聯(lián)系信息和手動接收到的時間,使用導致關節(jié)炎的量 ctrl-c/ctrl-v.
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.
我認為處理此問題的一種簡單方法是允許用戶將一封或多封電子郵件從 Outlook(它們目前都使用 Outlook 2007)拖到窗口中,允許我的應用程序提取必要的信息并發(fā)送它到后端系統(tǒng)進行存儲.
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.
然而,在谷歌上搜索這方面的信息幾個小時似乎表明關于這個看似基本的任務的信息令人震驚地缺乏.我認為這樣的事情在很多不同的環(huán)境中都會很有用,但到目前為止我所能找到的只是半生不熟的非解決方案.
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.
有人對如何做到這一點有任何建議嗎?因為我只是要閱讀郵件而不是發(fā)送任何東西或做任何邪惡的事情,所以最好有一個不涉及討厭的安全彈出窗口的解決方案,但任何事情都勝過根本無法做到這一點.
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.
基本上,如果我能獲得從 Outlook 中選擇、拖放的所有郵件項目的列表,我將能夠自己處理其余的事情!
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!
謝謝!
符文
推薦答案
我發(fā)現(xiàn)了一個很棒的 文章 應該完全符合您的需要.
I found a great article that should do exactly what you need to.
更新
稍作調(diào)整,我就可以讓那篇文章中的代碼在 WPF 中工作,以下是您需要進行的更改.
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.
將所有引用從 System.Windows.Forms.IDataObject 更改為 System.Windows.IDataObject
Change all references from System.Windows.Forms.IDataObject to System.Windows.IDataObject
在 OutlookDataObject 構造函數(shù)中,更改
In the OutlookDataObject constructor, change
FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
到
FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("_innerData", BindingFlags.NonPublic | BindingFlags.Instance);
將所有 DataFormats.GetFormat 調(diào)用更改為 DataFormats.GetDataFormat
Change all DataFormats.GetFormat calls to DataFormats.GetDataFormat
從
public void SetData(string format, bool autoConvert, object data)
{
this.underlyingDataObject.SetData(format, autoConvert, data);
}
到
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 應用程序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!