none
How to get the custom Properties(set using PropertyAccessor) of an appointment Item using EWS? RRS feed

  • Question

  • I have developed a Outlook COM AddIn,in which I am setting a custom Property on appointment item as follows.

    meeting.GetAssociatedAppointment(true).PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{c85eee26-0600-41ce-8f7f-1ec6ac431a44}/CostControlNumber", frmRegion.txtCostControlNumber.Text);

    Now,I want to access this property using EWS,could any one help me here and direct me in right direction..

    Below is the code which I tried..

    DateTime StartDate = dtTO.Value.Date; DateTime EndDate = dtFrom.Value.Date; ExtendedPropertyDefinition CustomProperty = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "CostControlNumber", MapiPropertyType.String); CalendarView cv = new CalendarView(StartDate, EndDate); cv.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, CustomProperty); Outlook.AddressList gal =Globals.ThisAddIn.Application.Session.GetGlobalAddressList(); if (gal != null) { Outlook.AddressEntries olEntries = gal.AddressEntries; try { int fTime = 0; foreach (Outlook.AddressEntry olEntry in olEntries) { int myval = olEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39050003"); if (myval == 7 ) { FolderId folderid = new FolderId(WellKnownFolderName.Calendar, new Mailbox(olEntry.GetExchangeUser().PrimarySmtpAddress)); if (fTime==0) { aps = service.FindAppointments(folderid, cv ); fTime = 1; } else { foreach (Microsoft.Exchange.WebServices.Data.Appointment item in service.FindAppointments(folderid, cv)) { aps.Items.Add(item); } } } } } catch (Exception) { //MessageBox.Show(ex.Message); //throw; } } #endregion

                                               

    foreach(Microsoft.Exchange.WebServices.Data.Appointment item in aps)
                {

                    try
                    {

    //this was working when I retrieved the appointment item(Outlook.AppointmentItem) from OOM for the current logged in user.
                        //UserProp = item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{c85eee26-0600-41ce-8f7f-1ec6ac431a44}/CostControlNumber");
                       foreach(ExtendedProperty extendedProperty in item.ExtendedProperties)
                       {
                           //manipulate extendedProperty value
                       }

                    }
                    catch
                    {
                    }

    }




    Point5Nyble


    • Edited by Point5Nyble Wednesday, November 25, 2015 4:44 PM heading
    Wednesday, November 25, 2015 4:25 PM

All replies

  • Your EWS Extended property definition is wrong eg in your DASL you have used

    http://schemas.microsoft.com/mapi/string/{c85eee26-0600-41ce-8f7f-1ec6ac431a44}/CostControlNumber

    Meaning your PropSetGuid is {c85eee26-0600-41ce-8f7f-1ec6ac431a44} so your Extended property definition should be

    ExtendedPropertyDefinition CustomProperty = new ExtendedPropertyDefinition(Guid.Parse("{c85eee26-0600-41ce-8f7f-1ec6ac431a44}"), "CostControlNumber", MapiPropertyType.String);

    Otherwise change your DASL to use PublicStrings GUID eg

    http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/CostControlNumber

    Cheers
    Glen

    Thursday, November 26, 2015 1:29 AM
  • I tried to modify that but the ExtendedProperties are empty.

    Please let me know,what other approach could I take ?

    I have used PropertyAccessor to set custom properties because I have to show those properties on Outlook UI too.

    Thanks



    Point5Nyble

    Thursday, November 26, 2015 5:42 AM
  • Try looking at the property on an Item using a MAPI editor like Outlook Spy of MFCMapi I would say you probably haven't set the Property Type correct eg is the property an Interger (can you post a screenshot of what the property looks like in a Mapi editor) if the property is an Interger then you need to define the property correctly eg MapiPropertyType.Interger

    It will work if you get the property definition correct but you will need to use a Mapi editor to find the correct definition.

    Cheers
    Glen

    Thursday, November 26, 2015 10:45 PM
  •  I tried to define as you have defined the 

    ExtendedPropertyDefinition CustomProperty = new ExtendedPropertyDefinition(Guid.Parse("{c85eee26-0600-41ce-8f7f-1ec6ac431a44}"), "CostControlNumber", MapiPropertyType.String);

    but was able to retrieve these custom property for only two items which were created earlier.

    So,I guess I made some changes due to which property may not be saving correctly(However I am able to read them using PropertyAccessor.getProperty)

    So,Instead I made change to DASL to use PublicStrings GUID and then also it didn't work.

    But when I changed this line 

    >>

    meeting.GetAssociatedAppointment(true).PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{c85eee26-0600-41ce-8f7f-1ec6ac431a44}/CostControlNumber", frmRegion.txtCostControlNumber.Text);

    to 

    meeting.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{c85eee26-0600-41ce-8f7f-1ec6ac431a44}/CostControlNumber", frmRegion.txtCostControlNumber.Text);

    I was able to fetch the customproperties.

    I am not sure why?? Because while retrieving the sustom property using EWS,I am working with the appointment item rather than a Meeting item.

    Thanks


    Point5Nyble

    Friday, November 27, 2015 5:43 AM
  • You need to look at the item with a MAPI editor this will tell you exactly what properties are available to be retrieved your just guessing at it otherwise. You need to also look at your logic also from the way your asking the question it seems like you confusing this a little eg

    >> Because while retrieving the sustom property using EWS,I am working with the appointment item rather than a Meeting item.

    That doesn't really make any sense ? A meeting is an appointment but as I said check the items with a MAPI editor because this will tell you exact values.

    Cheers
    Glen

    Sunday, November 29, 2015 9:27 PM
  • Meeting and Appointment Items are not same.. 

    Meeting has Recipients

    Appointment has no Recipients .

    Outlook also treats both the Objects differently.I asked this because,we can extract Associated Appointment from a Meeting.

    Hope I made my point clear.


    Point5Nyble

    Monday, November 30, 2015 4:41 AM