简体   繁体   English

使用 EWS 列出所有可用的扩展属性

[英]List all available extended properties using EWS

I'm trying to find a way to list ALL extended properties for set of calendar items using EWS.我正在尝试找到一种使用 EWS 列出日历项集的所有扩展属性的方法。

The problem is that all examples I managed to find online require me to know what those extended properties are, in advance.问题是我设法在网上找到的所有示例都要求我提前知道这些扩展属性是什么。 Here's the official MSDN example .这是官方的 MSDN 示例

What am I supposed to do if I do not know the IDs or names of extended properties?如果我不知道扩展属性的 ID 或名称,我该怎么办? Or if I don't even know if any extended properties exist at all?或者,如果我什至不知道是否存在任何扩展属性?

I've tried the following code but it returns an exception...我试过下面的代码,但它返回一个异常...

            var calendarItems = service.FindAppointments(WellKnownFolderName.Calendar, view);
            var propertySet = new PropertySet(AppointmentSchema.ExtendedProperties);
            service.LoadPropertiesForItems(calendarItems, propertySet);

Here's the exception:这是例外:

Microsoft.Exchange.WebServices.Data.ServiceResponseException: The request failed schema validation: The required attribute 'FieldURI' is missing.

There is no call in EWS to get all extended properties. EWS 中没有调用来获取所有扩展属性。 The idea behind extended properties is that applications use them to store app-specific data, so only that app needs to know the specifics on their properties.扩展属性背后的想法是应用程序使用它们来存储特定于应用程序的数据,因此只有该应用程序需要知道其属性的细节。

Extended MAPI can discover this information.扩展的 MAPI 可以发现此信息。 https://github.com/stephenegriffin/mfcmapi has a ton of sample code for different tasks, including iterating named properties. https://github.com/stephenegriffin/mfcmapi有大量用于不同任务的示例代码,包括迭代命名属性。

I was also looking similar and I just did a kind of reverse engineering.我看起来也很相似,我只是做了一种逆向工程。 Since the extended property is the combination of Id (integer) and data type which we could not know as they are not documented on any MSDN.由于扩展属性是 Id(整数)和数据类型的组合,我们无法知道,因为它们没有记录在任何 MSDN 上。 So, iterate 1 to some huge number like 15000 for string type property and find those which can be loaded successfully - this is the main trickest part which we can do by putting try-catch to bind that extended property.因此,对于字符串类型的属性,将 1 迭代为 15000 之类的大数字,然后找到那些可以成功加载的数字 - 这是我们可以通过放置 try-catch 来绑定该扩展属性来完成的最棘手的部分。 Then you could get the required one.然后你可以得到所需的一个。 Hope that helps.希望有帮助。

  List<int> allStringIds = new List<int>();
for (int i = 0; i <= 15000; i++)
{
    allStringIds.Add(i);
}

ParallelOptions options = new ParallelOptions
{
    MaxDegreeOfParallelism = 200,
    CancellationToken = CancellationToken.None,
};

Parallel.For(0, allStringIds.Count, options, index =>
{
    try
    {
     ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(index,
                   MapiPropertyType.String);
     latestMessage = EmailMessage.Bind(service, item.Id.UniqueId,
     new PropertySet(BasePropertySet.FirstClassProperties, extendedPropertyDefinition));
     _logger.Write("Supported string property id=" + index);
     supportedListId.TryAdd(index, index);
 }
 catch(Exception ex)
 {

 }
});

 foreach (var a in supportedListId)
 {
  ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(a.Key,
  MapiPropertyType.String);
  allExtendedPropertyDefinitions.Add(extendedPropertyDefinition);
 }
 latestMessage = EmailMessage.Bind(service, item.Id.UniqueId,
 new PropertySet(BasePropertySet.FirstClassProperties, allExtendedPropertyDefinitions));
 
 foreach (var extendedProperty in latestMessage.ExtendedProperties)
 {
 if (extendedProperty.PropertyDefinition != null && extendedProperty.PropertyDefinition.Tag != null)
 {
  if (extendedProperty.Value != null)
  {
     _logger.Write($"OMG... extendedProperty id={extendedProperty.PropertyDefinition.Id}," +
         $" name={ extendedProperty.PropertyDefinition.Name}, value={extendedProperty.Value}");
    }
   }
}   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM