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}");
}
}
}