如何使用 Outlook Interop 删除 UserProperty?
How to remove UserProperty with Outlook Interop?
我已经 运行 使用以下代码来添加 olText
类型的特定 UserProperty:
mailItem.UserProperties.Add(Name: "MyProperty", Type: OlUserPropertyType.olText);
我决定改用整数作为类型,并将代码更改为:
mailItem.UserProperties.Add(Name: "MyProperty", Type: OlUserPropertyType.olInteger);
然而,这给了我一个 COMException
说明 属性 名称已经存在,但类型不同。我什至不知道关闭我的应用程序后用户属性会保留。现在我似乎无法摆脱它!
我已经按照建议 here 进行了尝试,但是当我尝试使用 mailItem.UserProperties["MyProperty"]
检索 UserProperty
时,我得到 null
.
如何才能完全删除我添加的用户属性?我怎么才能看到它们?
使用 UserProperties.Find 方法为所请求的 属性 名称定位并 returns 一个 UserProperty
对象(如果存在)。只有找到后,您才可以调用 Delete
方法来删除现有的声明,添加一个具有新 属性 类型的新声明。
您不能保留相同的名称并更改 属性 类型 - 一旦命名的 MAPI 属性 用于特定类型,商店提供商就会记住它。
您需要更改 属性 名称。
我已经 运行 使用以下代码来添加 olText
类型的特定 UserProperty:
mailItem.UserProperties.Add(Name: "MyProperty", Type: OlUserPropertyType.olText);
我决定改用整数作为类型,并将代码更改为:
mailItem.UserProperties.Add(Name: "MyProperty", Type: OlUserPropertyType.olInteger);
然而,这给了我一个 COMException
说明 属性 名称已经存在,但类型不同。我什至不知道关闭我的应用程序后用户属性会保留。现在我似乎无法摆脱它!
我已经按照建议 here 进行了尝试,但是当我尝试使用 mailItem.UserProperties["MyProperty"]
检索 UserProperty
时,我得到 null
.
如何才能完全删除我添加的用户属性?我怎么才能看到它们?
使用 UserProperties.Find 方法为所请求的 属性 名称定位并 returns 一个 UserProperty
对象(如果存在)。只有找到后,您才可以调用 Delete
方法来删除现有的声明,添加一个具有新 属性 类型的新声明。
您不能保留相同的名称并更改 属性 类型 - 一旦命名的 MAPI 属性 用于特定类型,商店提供商就会记住它。
您需要更改 属性 名称。