2

I'm trying to find a way to list ALL extended properties for set of calendar items using 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.

What am I supposed to do if I do not know the IDs or names of extended properties? 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.

MBender
  • 5,395
  • 1
  • 42
  • 69

2 Answers2

7

There is no call in EWS to get all extended properties. 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. https://github.com/stephenegriffin/mfcmapi has a ton of sample code for different tasks, including iterating named properties.

Community
  • 1
  • 1
Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
  • I second @Jason. The basic idea behind extended properties is to enable mobile/web applications to store their custom data associated with each outlook item so that every time you access that particular outlook item, you process it accordingly. – Baqer Naqvi Apr 04 '17 at 13:42
  • Problem wasn't severe before, as MAPI was the alternative. Nowadays when HMA kicked in and MAPI doesn't work with modern authentication (unless Outlook is used to authenticate) it is not answer anymore. Try use MFCMAPI, doesn't work. Both Graph and EWS doesn't support extracting all properties. For server it shouldn't be a problem, since MAPI did that in Exchange on premise. I am trying to understand why it's such problem for Graph/EWS to support it too? – Myfero Mar 24 '22 at 14:23
1

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. 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. 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}");
    }
   }
}   
Prakash
  • 422
  • 1
  • 12
  • 31