Unable to set item datetime (as PT_SYSTIME) using PropertyAccessor in Outlook VSTO

2

Setting a datetime column in Outlook to a c# DateTime value with the following code

documentItem.PropertyAccessor.SetProperty(
    "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/TestDate/0x0000001F",
    documentItem.PropertyAccessor.LocalTimeToUTC(DateTime.Now));

converts the columnvalue to type PT_APPTIME, which can't be displayed, sorted etc. in an Outlook-Tableview.

All my tries to set the value as a PT_SYSTIME (eg. creating my own PROPVARIANT struct, Marshal.StructureToPtr, ...) failed with various exceptions.

Is there a way to set a datetime value without using redemption libraries, which is overkill for this purpose?

c#
outlook
vsto
outlook-addin
asked on Stack Overflow Nov 10, 2015 by eWilli • edited Jan 26, 2017 by eWilli

2 Answers

0

Is TestDate is the name of the user property? Keep in mind that OOM does not understand the type (0x0000001F) in a property and it will treat "TestDate/0x0000001F" as the name of the property.

Try to use UserProperties.Add instead.

0

I've had the same problem some time ago; after much trial and error with the PropertyAccessor I've resorted to passing the MAPIOBJECT property of the MailItem to a method in a C++/CLI extension library project since it's the easiest way to combine managed objects and unmanaged header files (i.e. the Outlook 2010 MAPI API headers) to set the property using the MAPI interfaces directly.

I first used Marshal::GetIUnknownForObject to get an IUnknown* pointer from the MAPIOBJECT, then used QueryInterface on it with the IID_IMessage and IID_IMAPIProp ids to get the respective interfaces and in turn used IMAPIProp's GetIDsFromNames, SetProps and SaveChanges to set the property.

(I got the general idea from this codeproject article and adapted it to my needs...)

Considering how Outlook treats PT_APPTIME values in view columns (i.e. being totally unable to do anything with them at all and instead just showing a blank value) I doubt the PropertyAccessor behaviour with regards to dates could be called anything other than a bug; it really shouldn't be neccessary to go to those lengths for such a (seemingly) simple operation... :(

answered on Stack Overflow Nov 16, 2015 by Leak

User contributions licensed under CC BY-SA 3.0