C# ComAddIn: Imitate "Drag & Drop"

Joined
Dec 15, 2005
Messages
4
Reaction score
0
Hello everyone!

I would like to imitate Outlooks Drag & Drop functionality on this case:
When you drag and drop an email message into the body of a Outlook Task Item you normally receive a clickable link (named like the emails subject), which, when clicked, opens the dropped email.

I would like to create such a link using a ComAddIn. So far I tried and succeeded to add an email to a task item as an attachment. the email also appears in the body of the task item but is not clickable to open the email.

my source code looks like this:

Code:
using MOIO = Microsoft.Office.Interop.Outlook;
...
//get the task item
MOIO.NameSpace olNS = ((MOIO.Application)applicationObject).GetNamespace("MAPI"); 
MOIO.TaskItem iTaskItem = (MOIO.TaskItem) olNS.GetItemFromID(itemEntryID, itemStoreID);
//get the mail item (same subject)
MOIO.MailItem iMailItem = null;
MOIO.MAPIFolder oMailFolder = getFolder("Posteingang");
MOIO.Items oItems = oMailFolder.Items;
foreach (MOIO.MailItem mail in oItems){
    if (mail.MessageClass == "IPM.Note" && mail.Subject.Equals(iTaskItem.Subject.ToString())) {
        iMailItem = mail;
    }
}
//add mail as attachment to task item
iTaskItem.Attachments.Add(iMailItem, MOIO.OlAttachmentType.olByReference, iTaskItem.Body.Length+1, iMailItem.Subject);
...
Can I use the method Attachments.Add to achieve this? do i have to alter the parameters?

in the attachment you can see the result. left attachment manually, right attachment programmatically

I appreciate an suggestions!

Ciao Ole Jaekel
 

Attachments

  • iTaskItem.Attachment.Add.GIF
    iTaskItem.Attachment.Add.GIF
    20.7 KB · Views: 140
Joined
Dec 15, 2005
Messages
4
Reaction score
0
Hello again!
can't someone tell, if it's possible to reproduce a drag and drop item? microsoft did it, so it should be reproducable, shouldn't it?
 
Joined
Dec 15, 2005
Messages
4
Reaction score
0
Problem Solved!

now after a time distance i can answer my question myself.
i used this line to add the attachment finally in the way i wanted it in the first place:

Code:
//add mail as attachment to task item
iTaskItem.Attachments.Add(iMailItem, [b]MOIO.OlAttachmentType.olByValue[/b], iTaskItem.Body.Length+1, iMailItem.Subject);
...

please note that i just changed the second parameter of the function Attachments.Add()
this second argument defines the type of the attachment and can take four different values:
Microsoft.Office.Interop.Outlook.OlAttachmentType.olByReference,
Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue,
Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem or
Microsoft.Office.Interop.Outlook.OlAttachmentType.olOLE

you have to take ...olByValue if you want to look at the attachment by double-clicking on it as i wanted to.

i hope this helps someone else too.

ciao Ole
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top