0

I need to read and write a custom column that I created in a process mailbox (public mailbox?) within Outlook.

I think I'm supposed to use the ExtendedPropertyDefinition somehow, however, I do not know how. I do not have the GUID for the column, if this makes sense.

I've named the custom column 'Engineer', and used this code, but I get 0 count for the ext props.

ExtendedPropertyDefinition myExtDef= 
       new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings,
                                      "Engineer",
                                      MapiPropertyType.String);

And then

PropertySet propertySet = 
                 new PropertySet(BasePropertySet.FirstClassProperties, myExtDef);

Finally

foreach (Item item in findResults)
{ 
    EmailMessage message = 
               EmailMessage.Bind(service, item.Id, new PropertySet(propertySet));
}

As I debug and check an 'item' in findResults, I see the subject property and all that, but the ExtendedProperties count is 0. Looks like a problem with the way I define my extended properties to me.

Can anybody help me how to read and write the custom column?

Edit: I'm now not so sure if this can be achieved at all using the managed API.. If there's anyone out there with some ideas, I'll take it. I've checked all the below, but to no avail.

Accessing custom contacts using EWS managed API http://msdn.microsoft.com/en-us/library/office/dd633697(v=exchg.80).aspx

And others...

Community
  • 1
  • 1
Ashton
  • 1,265
  • 14
  • 23

1 Answers1

2

Marton,

It looks as though you have the basic concept correct for working with extended properties. It's hard to say where the issue is because there are only a few snippets of your code. Here is an example that you should be able to build from. It creates a new mail message, sets the extended property and then saves the message (to the drafts folder).

// Create a definition for the extended property.
ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "Engineer", MapiPropertyType.String);

// Create an e-mail message that you will add the extended property to.
EmailMessage message = new EmailMessage(service);
message.Subject = "Saved with custom ExtendedPropertyDefinition.";
message.Body = "The Engineer custom value is stored within the extended property.";
message.ToRecipients.Add("user@contoso.com");

// Add the extended property to an e-mail message object.
message.SetExtendedProperty(extendedPropertyDefinition, "Save some customer value");
message.Save();

Now to verify the message was created with the extended property you can use FindItems. The following example will search the drafts folder for messages with the "Engineer" extended property.

ItemView view = new ItemView(10);
// Create a definition for the extended property.
ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "Engineer", MapiPropertyType.String);

// Create a search filter the filters email based on the existence of the extended property.
SearchFilter.Exists customPropertyExistsFilter = new SearchFilter.Exists(extendedPropertyDefinition);

// Create a property set that includes the extended property definition.
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, extendedPropertyDefinition);

// Search the drafts folder with the defined view and search filter.
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Drafts, customPropertyExistsFilter, view);

// Search the e-mail collection returned in the results for the extended property.
foreach (Item item in findResults.Items)
{
    Console.WriteLine(item.Subject);

    // Check whether the item has the custom extended property set.
    if (item.ExtendedProperties.Count > 0)
    {
        // Display the extended 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);
        }
    }
    else
    {
        Console.WriteLine(" This email does not have the 'Engineer' extended property set on it");
    }
}

In order to view and update these extended properties in a custom form in Outlook there is some additional work that needs to be done. Outlook forms use an additional property to store extended properties as a binary field. The PidLidPropertyDefinitionStream needs to be modified as well as the extended properties. Unfortunately EWS Managed API does not do this for you, so you'll have to write some code to read/update this property yourself. I don't have any example code to show you, but here are some links about the property structure that will help you along the way:

Bob Bunn
  • 613
  • 3
  • 7
  • Hi Bob, I appreciate your response, you are a beacon of hope :) I can use the above code, however, it doesnt achieve what I need. I added an extra column to outlook. The data stored in that column... Is that even accessible by the ExtendedProperties? (If I use the above to create a new mail, the "Engineer" column is still blank. The extra column was addedd according to [link](http://msdn.microsoft.com/en-us/library/office/ff868399(v=office.15).aspx) – Ashton Mar 17 '14 at 12:00
  • Marton, I did some additional testing with a message in the Drafts folder as my example shows. I created a custom column for the message called "TestColumn" and I was able to view the contents of the column using the code above by changing the ExtendedPropertyDefinition to look for the new column name. Bottom line is that these values are being stored in the PublicStrings extended properties set. Something in Outlook is keeping the original value for Engineer from showing, but if I update it using the Outlook form, my code shows the new value. I'll let you know if I find more information. – Bob Bunn Mar 17 '14 at 14:37
  • Thank you so much. I'm looking forward for your advice. In the meantime I've seen similar behavior: I entered a value to the Engineer column in one of the mails via Outlook, and your code did find it as having more than 0 ExtendedProperty, listed the name ("Engineer") but for value it shows blank. (It should be "test" - how original, I know :) ) – Ashton Mar 17 '14 at 16:41
  • interestingly, the following yields "its null", so apparently after writing in the value in Outlook, it gets stored elsewhere. ` if (extendedProperty.Value == null) { Console.WriteLine("its null"); }` – Ashton Mar 17 '14 at 18:40
  • Marton, I found some more information regarding these extended properties. Outlook is also saving them in a binary property called PidLidPropertyDefinitionStream. I added some links to the answer above that may be able to help you further. – Bob Bunn Mar 17 '14 at 19:20
  • Hi Bob, I really appreciate your response. I understand that this is a missing element from the API. I also understand that you dont have code example... Is there someone around you who might be able to help out with code? I have absolutely no clue how to start modifying those binaries with C#. Even if you don't thanks a million for your time. – Ashton Mar 17 '14 at 19:31