1
votes

I create a TaskRequestItem via .NET Outlook Interop API and add my own UserProperty. (I use the already running Outlook instance) At the end I display the item in Outlook and the 1st process is over.

In my Outlook is running a VSTO Addin, which listen to the event ItemSend. If now I send the TaskRequestItem in Outlook, I cannot find in the Event ItemSend on the item any UserProperties!

I also tried with ItemProperties and the PropertyAccessor. Same problem, all properties have disappeared!

If I try this with a MailItem, then it works!

Adding the properties works first, because I can read them out right after adding them in 1st step...

Part 1 to create new item with interop api:

Microsoft.Office.Interop.Outlook.Application outlook = Marshal.GetActiveObject("Outlook.Application") as OutlookApplication;

...

TaskItem item = outlook.CreateItem(OlItemType.olTaskItem);
var task = item.Assign();
var guid = Guid.NewGuid().ToString();
var userProperty = item.UserProperties.Add("My GUID", OlUserPropertyType.olText, true);
userProperty.Value = guid;
task.Save();
task.Display();

...

Part 2 ItemSend in VSTO Addin

private void MyAddIn_ItemSend(object item, ref bool cancel)

...

var oItm = item as TaskRequestItem;
foreach (UserProperty property in oItm.UserProperties)
{
    if (property.Name == "My GUID")
    {
        Console.WriteLine("My GUID: " + property.Value);
    }
}
1
Looks like a Microsoft bug?Andreas

1 Answers

0
votes

The Task itself is never sent - it remains in the Tasks folder with all the user properties intact. What is sent is a TaskRequestItem object, which is distinct from the original lask object. You can call TaskRequestItem.GetAssociatedTask to retrieve the original Task object and copy your custom properties.