Drag & Drop of Outlook message + attachments to VB.Net form

  • Thread starter Thread starter David Anderson
  • Start date Start date
D

David Anderson

Does anyone know how to drag&drop a message with attachments from Outlook
(2002 or 2003) in to a VB.Net windows form.
This is really stumping me. I've spent a fair amount of time trying to find
a solution on the internet, with limited success.

I do have code to drag an attachment directly from Outlook to a form, but
not a whole message.
I want to have access to an object reprensenting the message so I can bust
out the message and attachments individually.

I have implemented a solution involving dragging the e-mail message from
Outlook to the desktop, then from the desktop to the windows form, but the
users don't want to do that and I don't think they should have to.

I've seen libraries and code that seem to make this easy using VB6, C++, or
COM, but almost nothing in .Net except simple examples of either files or
tree items, not Outlook e-mails directly onto VB.Net Winforms.

Any help appreciated.
Dave Anderson.
 
David,

Mostly is implementing code in VBNet simple when you know the VBA code used
in outlook, did you ask this already in a VBA Outlook newsgroup?

Cor
 
David,
Unfortunately the format Outlook uses for Drag & Drop is not defined. You
can use the IDataObject.GetFormats to see the formats that Outlook is
offering to your app. However how to use the interesting formats that
probably contain the actual message is not defined.

Hope this helps
Jay
 
I have probably tried the same things that you have with the same
results. I do have a potential workaround. You have been trying to
get to the MailItem by looking at the DragEventArgs. What you should
be able to do is use the DragEventArgs to determine if the dropped
item is an Outlook item. (I think that the objectdescriptor format
will have the text "Outlook".) If it is Outlook then use the Outlook
object model to get the message with code similar to:

Outlook._Application myOlApp=new Outlook.ApplicationClass();
Outlook._Explorer myExp=myOlApp.ActiveExplorer();
Outlook._MailItem myMailItem=(Outlook.MailItem)myExp.Selection.Item(1);
string txtBody=myMailItem.Body;

Now you have the MailItem and you can do whatever you like. Since
this is on the drop event the ActiveExplorer should be the outlook
instance that you dragged from. Likewise the item you are dragging
would still be the active selection. Sorry I gave you the snippet in
C#, but you get the point. Hope that helps.
 
RD,
Interesting kludge, it just might work.

If I find time I may look at this later.


Jay
 
Back
Top