无法在Outlook VSTO中使用PropertyAccessor设置项目日期时间(如PT_SYSTIME) [英] Unable to set item datetime (as PT_SYSTIME) using PropertyAccessor in Outlook VSTO

查看:134
本文介绍了无法在Outlook VSTO中使用PropertyAccessor设置项目日期时间(如PT_SYSTIME)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码将Outlook中的datetime列设置为c#DateTime值

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));

将columnvalue转换为PT_APPTIME类型,该类型无法在Outlook-Tableview中显示,排序等.

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

我所有尝试将值设置为PT_SYSTIME的尝试(例如,创建我自己的PROPVARIANT结构Marshal.StructureToPtr等)都失败了.

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?

推荐答案

前段时间我遇到了同样的问题;在对PropertyAccessor进行了多次试验和错误之后,我求助于将MailItemMAPIOBJECT属性传递给C ++/CLI扩展库项目中的方法,因为这是组合托管对象和非托管头文件的最简单方法(即Outlook 2010 MAPI API标头)直接使用MAPI接口设置属性.

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.

我首先使用Marshal::GetIUnknownForObjectMAPIOBJECT获取IUnknown*指针,然后在其上将QueryInterfaceIID_IMessageIID_IMAPIProp id一起使用以获取相应的接口,并依次使用GetIDsFromNamesSetPropsSaveChanges来设置属性.

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...)

考虑到Outlook如何处理视图列中的PT_APPTIME值(即完全无法对它们执行任何操作,而只是显示空白值),我怀疑关于日期的PropertyAccessor行为是否可以称为其他任何值而不是臭虫;对于这样的(看似)简单的操作,确实不必花那么长的时间...:(

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... :(

这篇关于无法在Outlook VSTO中使用PropertyAccessor设置项目日期时间(如PT_SYSTIME)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆