0

I am running code that looks to add an extended property along with a value. Seems to run fine. When I iterate over the MailItems, I do not see any evidence of the extended property.

Code to extend:

EmailMessage email2 = EmailMessage.Bind(service, result.Items[0].Id);
Guid MyPropertySetId = new Guid("{C11FF724-AA03-4555-9952- 
8FA248A11C3E}");
ExtendedPropertyDefinition extendedPropertyDefinition = new 
ExtendedPropertyDefinition(MyPropertySetId, "ServiceCat", 
MapiPropertyType.String);
email2.SetExtendedProperty(extendedPropertyDefinition, "Level2 big daddy");
email2.Update(ConflictResolutionMode.AlwaysOverwrite);

Code to read extended property:

   foreach (Item item in result.Items)
        {
            Console.WriteLine(item.Subject);
            if (item.ExtendedProperties.Count > 0)
            {
                // Display the name and value of the extended property.
                foreach (ExtendedProperty extendedProperty in item.ExtendedProperties)
                {
                    Console.WriteLine(" Extended Property Name: " + extendedProperty.PropertyDefinition.Name);
                    Console.WriteLine(" Extended Property Value: " + extendedProperty.Value);
                }
            }
        }

I have tried to reconnect to iterate over emails to see if extended property is there but array length remains 0. I.e. the foreach never kicks in.

I am assuming extended preoprty is saved at the exchange "email2.Update(ConflictResolutionMode.AlwaysOverwrite)" and should be able to be read back

Any advice appreciated.

1 Answers1

1

You need to load the extended property using a Property set before you will be able to enumerate it on a Message eg

        PropertySet psPropSet = new PropertySet();
        psPropSet.Add(extendedPropertyDefinition );
        ItemView itemView = new ItemView(1000);
        itemView.PropertySet = psPropSet;

You can then just use TryGetProperty to Get the extendedproperty if set

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • Thanks, I can see the property coming through now. I wish to add the extended properties to the mail items of many different group mailboxes. At a later stage I wish to append the values to the property. Can I use the same GUID for appending the extended property across mailboxes? – David Jones Apr 01 '19 at 06:09
  • Or, can I use : – David Jones Apr 01 '19 at 06:15
  • You should use the same GUID don't start creating lot of random extended properties all you need is one else you will start to have issue with extended property exhaustion. You one need to define one for what your trying to do and it will work across as many mailbox as you need. – Glen Scales Apr 02 '19 at 00:41