簡體   English   中英

使用 EWS 列出所有可用的擴展屬性

[英]List all available extended properties using EWS

我正在嘗試找到一種使用 EWS 列出日歷項集的所有擴展屬性的方法。

問題是我設法在網上找到的所有示例都要求我提前知道這些擴展屬性是什么。 這是官方的 MSDN 示例

如果我不知道擴展屬性的 ID 或名稱,我該怎么辦? 或者,如果我什至不知道是否存在任何擴展屬性?

我試過下面的代碼,但它返回一個異常...

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

這是例外:

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

EWS 中沒有調用來獲取所有擴展屬性。 擴展屬性背后的想法是應用程序使用它們來存儲特定於應用程序的數據,因此只有該應用程序需要知道其屬性的細節。

擴展的 MAPI 可以發現此信息。 https://github.com/stephenegriffin/mfcmapi有大量用於不同任務的示例代碼,包括迭代命名屬性。

我看起來也很相似,我只是做了一種逆向工程。 由於擴展屬性是 Id(整數)和數據類型的組合,我們無法知道,因為它們沒有記錄在任何 MSDN 上。 因此,對於字符串類型的屬性,將 1 迭代為 15000 之類的大數字,然后找到那些可以成功加載的數字 - 這是我們可以通過放置 try-catch 來綁定該擴展屬性來完成的最棘手的部分。 然后你可以得到所需的一個。 希望有幫助。

  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