Drag’n’drop one or more mails from Outlook to C# WPF application

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.

Leave a Comment