通过EWS加载扩展属性 [英] Loading extended properties via EWS
问题描述
我可以在属性集中指定扩展属性,作为finditems查询视图的一部分。但是,当我使用类似的方法来读取EmailMessage的扩展属性时,我已经明确加载了相同的属性,我无法引用它们。
I can read extended properties when specifying them in a property set as part of the view of a finditems query. However, when I use a similar approach to read extended properties of an EmailMessage I have explicitly loaded with the same properties I can't refer to them.
正确的加载方式是什么?参考 扩展属性?
What is the correct way to load and reference extended properties?
谢谢
Phil。
private 静态 void ProcessEmail( EmailMessage 邮件) { private static void ProcessEmail(EmailMessage mail)
{
PropertySet ps = new PropertySet ( < span style ="color:#2b91af; font-size:x-small"> BasePropertySet ps.Add( PropertySet ps = new PropertySet(BasePropertySet.FirstClassProperties);
ps.Add( new ExtendedPropertyDefinition (MyPropertySetId, " MyProp" , MapiPropertyType 。字符串)); // ...添加一些其他自定义属性 mail.Load(ps);
mail.Load(ps); string test = mail.ExtendedProperties [0] .PropertyDefinition.Name + " " + mail.ExtendedProperties [0] .Value; //在线上方工作,但如果我必须找到每个项目 $,这很乏味b $ b // above line works but tedious if I have to find each item
ExtendedPropertyDefinition df = new ExtendedPropertyDefinition (MyPropertySetId, " MyProp" , MapiPropertyType 。字符串); ExtendedPropertyDefinition df = new ExtendedPropertyDefinition(MyPropertySetId, "MyProp", MapiPropertyType.String);
对象 myPropObj = null ; mail.TryGetProperty(df, object myPropObj = null;
mail.TryGetProperty(df, out myPropObj); //总是空的??? } 我无法重现您的问题。以下代码对我来说很合适: I cannot reproduce your problem. The following code works just fine for me: 这篇关于通过EWS加载扩展属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
推荐答案
Guid myPropGuid = new Guid("{A71E6D47-619E-45ed-9CEF-23788EB5D057}");
ExtendedPropertyDefinition myProp = new ExtendedPropertyDefinition(
myPropGuid,
"MyProp",
MapiPropertyType.String);
// First create a message with the extended property set
EmailMessage message = new EmailMessage(service);
message.Subject = "Test EP";
message.SetExtendedProperty(myProp, "Test");
message.Save();
// Now verify we can retrieve the extended property
EmailMessage otherMessage = EmailMessage.Bind(
service,
message.Id,
new PropertySet(myProp));
// First with the indexer
try
{
Console.WriteLine("Using the indexer: " + otherMessage[myProp].ToString());
}
catch
{
Console.WriteLine("Unable to get the property value with the indexer.");
}
// Then with TryGetPropertyValue
object propValue;
if (otherMessage.TryGetProperty(myProp, out propValue))
{
Console.WriteLine("Using TryGetProperty: " + propValue.ToString());
}
else
{
Console.WriteLine("Unable to get the property value with TryGetProperty.");
}
Console.ReadLine();