none
Accessing UserProperties through EWS RRS feed

  • Question

  • Hi

    I am trying to access UserProperties that are attached to the appointment items through EWS. (EWS 2007)

    I added the userproperty like this.

    Outlook.UserProperty prop = (outlookItem as Outlook.AppointmentItem).UserProperties.Add("BookingType", Outlook.OlUserPropertyType.olNumber, true, Type.Missing);
    prop.Value = value;

    Now I am trying to retrieve appointment item and the user property using EWS through the below code..  The appointment items are retrieved but the UserProperties do not seem to be there.



    // Create the request for all Calendar items between the specified dates
                FindItemType findItemRequest = new FindItemType();
    //Filter by date range
                CalendarViewType calendarView = new CalendarViewType();
                calendarView.StartDate = StartDate;
                calendarView.EndDate = EndDate;
                calendarView.MaxEntriesReturned = 1000;
                calendarView.MaxEntriesReturnedSpecified = true;
                findItemRequest.Item = calendarView;

    // We want items from the Calendar "Folder"
                DistinguishedFolderIdType[] folderIDs = { new DistinguishedFolderIdType { Id = DistinguishedFolderIdNameType.calendar } };
                if (EmailAddress != null)
                {
                    folderIDs[0].Mailbox = new EmailAddressType();
                    folderIDs[0].Mailbox.EmailAddress = EmailAddress;
                }

                findItemRequest.ParentFolderIds = folderIDs;


    //Extended properties
                List<BasePathToElementType> extendedFields = new List<BasePathToElementType>();
                extendedFields.Add(CreateExtendedPropertyType("BookingType", MapiPropertyTypeType.Integer));

     //Base properties
                List<BasePathToElementType> elements = new List<BasePathToElementType>();
                elements.Add(new PathToUnindexedFieldType() { FieldURI = UnindexedFieldURIType.calendarLocation });
                elements.Add(new PathToUnindexedFieldType() { FieldURI = UnindexedFieldURIType.itemSubject });
                elements.Add(new PathToUnindexedFieldType() { FieldURI = UnindexedFieldURIType.calendarStart });
                elements.Add(new PathToUnindexedFieldType() { FieldURI = UnindexedFieldURIType.calendarEnd });

    elements.AddRange(extendedFields);

    // Bring back only set of properties
                ItemResponseShapeType itemProperties = new ItemResponseShapeType();
                itemProperties.BaseShape = DefaultShapeNamesType.IdOnly;
                itemProperties.AdditionalProperties = elements.ToArray();
                findItemRequest.ItemShape = itemProperties;

    // Shallow traversal
                findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
    // Send request, receive response
                FindItemResponseType findItemResponse = esb.FindItem(findItemRequest);

    ArrayOfResponseMessagesType responseMessages = findItemResponse.ResponseMessages;
    ResponseMessageType responseMessage = responseMessages.Items[0];

    if (responseMessage is FindItemResponseMessageType)
                {
                    FindItemResponseMessageType msgType = (responseMessage as FindItemResponseMessageType);
                    FindItemParentType parentType = msgType.RootFolder;

                    object obj = parentType.Item;
                    if (obj is ArrayOfRealItemsType)
                    {
                        ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType);

    if (items.Items != null) 
                        {
                            foreach (ItemType it in items.Items)
                            {
                                if (it is CalendarItemType)
                                {
                                    CalendarItemType cal = (CalendarItemType)it;

    ..................

    if (cal.ExtendedProperty != null && cal.ExtendedProperty.Length > 0)
                                    {
                                        foreach (ExtendedPropertyType t in cal.ExtendedProperty)
                                        {
                                            if (t.Item != null)
                                            {
                                                if (t.ExtendedFieldURI.PropertyName == "BookingType")
                                                {
                                                    int bookingType = (Int32.Parse(t.Item.ToString()));

          }
                                                }
                                        }

                                    }
                            }

    ..........................................................................

    private PathToExtendedFieldType CreateExtendedPropertyType(string propertyName, MapiPropertyTypeType type)
            {
                return new PathToExtendedFieldType()
                {
                    //PropertySetId = "81F59DF0-1F57-44BB-A43A-4E26E43B3BA2",
                    //PropertySetId = "00020329-0000-0000-C000-000000000046",
                    PropertyName = propertyName,
                    DistinguishedPropertySetId = DistinguishedPropertySetType.PublicStrings,
                    DistinguishedPropertySetIdSpecified = true,
                    PropertyType = type,

                };
            }

    ............................................................................

    I dont understand what is wrong with this code. 

    Please help.

    Thanks in advance

    G



    • Edited by gr_gr Tuesday, March 19, 2013 11:43 AM
    Tuesday, March 19, 2013 11:41 AM

All replies

  • Hi

    I also tried the below code

    Microsoft.Exchange.WebServices.Data.ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Url = new Uri("https://url/ews/exchange.asmx");
                service.UseDefaultCredentials = true;

                FolderId _cal = new FolderId(WellKnownFolderName.Calendar, new Mailbox(EmailAddress));
                CalendarView _calendarView = new CalendarView(StartDate, EndDate);
                _calendarView.Traversal = ItemTraversal.Shallow;
                ExtendedPropertyDefinition CustomProperty = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "BookingType", MapiPropertyType.Integer);
                _calendarView.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, CustomProperty);
                FindItemsResults<Appointment> results = service.FindAppointments(_cal, _calendarView);
                Log.WriteToFile("Results = " + results.Count());
                foreach (Appointment app in results)
                {
                    Log.WriteToFile("Result = " + app.ExtendedProperties.Count);
                    foreach (var prop in app.ExtendedProperties)
                    {
                        Log.WriteToFile(prop.PropertyDefinition.Name + "   " + prop.Value.ToString());
                    }
                }

    Again the appointments are retrieved but the extended property count is 0.

    How can I get the properties I am looking for. Please help.

    Thanks

    G

    Wednesday, March 20, 2013 9:46 AM
  • OK, when you add user property, you add it as Missing type but when you retrieve it, you specify it as Integer type.
    Friday, March 22, 2013 8:13 PM