David Brunelle
David Brunelle

Reputation: 6450

drag and drop Outlook attachment from Outlook in to a WPF datagrid

I saw this code ealier about drag and dropping attachment files (http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C) from Outlook into Windows Form and it works fine in windows Forms, but I can't seem to make it work with WPF. I tried to simply change System.windows.form.IDataObject to System.Windows.IDataObject but it doesn't work (as I should have guessed).

I also simply tried to get the content of the e.Data FileContents but always get errors (which seems to be the case to everyone when I check on the web).

Did anyone ever did drag and dropping attachment from Outlook to WPF ? I am at a complete loss.

Edit : I am not trying to get file from a Windows Explorer windows ( I do but I know how to). It's really the whole getting attachment from Outlook directly that doesn't work . I am fully aware too that I could simple take the file from outlook into a temp folder and then drop it into my program, but I would like to avoid this unncessary step if possible.

Upvotes: 4

Views: 4821

Answers (1)

David Brunelle
David Brunelle

Reputation: 6450

so in the end I was able to find out a link where someone did exactly that :

https://gist.github.com/MattyBoy4444/521547

For those who wonders. Here is what I did exactly.

  • Create a new project in C# (my code is in VB) and add the code to it
  • Reference the new project in my main project to be able to use it
  • In my drop Event, check whether or not I had the "FileGroupDescriptorW" object in the drop data and called the method if I do to retrieve the files.

Here is the complete code

If obj.GetDataPresent("FileGroupDescriptorW") Then 'Outlook
    Dim oOutLookObj As New Helpers.OutlookDataObject(e.Data)
    Dim StrFiles() As String = oOutLookObj.GetData("FileGroupDescriptorW")
    Dim contentStream() As System.IO.MemoryStream = oOutLookObj.GetData("FileContents")
    ' Do intended work...
End if 

The names of the files are in StrFiles and the content are found in the streams. Both have the same array size and are order correctly.

Upvotes: 4

Related Questions