Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

I have tried various ways to search for extended properties within calendar appointment, without any success. I am making use of C# (Web Services), VS 2008. Can any please point me in the right direction?

[edit]
I have a VSTO application that puts a Guid into each Appointment user property. When by making use of EWS I want to retrieve all the Extended Properties for that resource / boardroom. I am making use of C# (Web Service Project), VS2008 and Exchange 2010. So, first of all, is it possible to do this? And if so, how can I achieve this?
[edit]

I do get a list of all appointment within the resource by performing the following, but when I call the ExtendedProperty the value is null for each one, and I know for two of the items there are values.

C#
foreach (ItemType it in items.Items)
{
   if (it is CalendarItemType)
   {
      CalendarItemType cal = (CalendarItemType)it;
      if (cal.ExtendedProperty != null)
          tmp.Add(new ExtendedAppointmentData()
              {
                  EndDate = cal.End,
                  StartDate = cal.Start,
                  EventID = new Guid(cal.ExtendedProperty[0].Item.ToString()),
                  AppointmentStatus = cal.LegacyFreeBusyStatus.ToString()
              });
    }
}


Many thanks in advance.
Kind regards,
Posted
Updated 19-Feb-10 2:32am
v4

1 solution

The following 'code dump' solved my problem (have a close look at the property DistinguishedPropertySetType.PublicStrings made a world of difference!!):

/// <summary>
/// Gets the all calendar data as well as extended property data of a specific resource mailbox.
/// </summary>
/// <param name="mailbox">The specified resource mailbox - boardroom email address.</param>
/// <param name="startDate">The start date of the calendar view.</param>
/// <param name="endDate">The end date of the calendar view.</param>
/// <param name="boardRoomID">The board room ID.</param>
/// <returns>
/// returns a collection of appointments related as well as the extended property data to the specified resource mailbox
/// </returns>
/// <exception cref="System.Exception">Represents errors that occur during application execution.</exception>
public List<ExtendedAppointmentData> GetExtendedPropertyData(string mailbox, DateTime startDate, DateTime endDate, string boardRoomID)
{
    if (Convert.ToBoolean(ConfigurationManager.AppSettings["remotecertificatevalidation"]))
        ServicePointManager.ServerCertificateValidationCallback =
            delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
            {
                return true;
            };
    ExchangeServiceBinding esb = new ExchangeServiceBinding();
    esb.Url = ConfigurationManager.AppSettings["exchangeService2010"];
    esb.Credentials = new NetworkCredential("test", "password", "domain.local");
    List<ExtendedAppointmentData> tmp = new List<ExtendedAppointmentData>();
    // Form the FindItem request.
    FindItemType findItemRequest = new FindItemType();
    CalendarViewType calendarView = new CalendarViewType();
    calendarView.StartDate = startDate;
    calendarView.EndDate = endDate;
    calendarView.MaxEntriesReturned = 100;
    calendarView.MaxEntriesReturnedSpecified = true;
    findItemRequest.Item = calendarView;
    // Define which item properties are returned in the response.
    ItemResponseShapeType itemProperties = new ItemResponseShapeType();
    // Use the Default shape for the response.
    //itemProperties.BaseShape = DefaultShapeNamesType.IdOnly;
    itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
    findItemRequest.ItemShape = itemProperties;
    DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
    folderIDArray[0] = new DistinguishedFolderIdType();
    folderIDArray[0].Id = DistinguishedFolderIdNameType.calendar;
    folderIDArray[0].Mailbox = new EmailAddressType();
    folderIDArray[0].Mailbox.EmailAddress = mailbox;
    findItemRequest.ParentFolderIds = folderIDArray;
    // Define the traversal type.
    findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
    try
    {
        // Send the FindItem request and get the response.
        FindItemResponseType findItemResponse = esb.FindItem(findItemRequest);
        // Access the response message.
        ArrayOfResponseMessagesType responseMessages = findItemResponse.ResponseMessages;
        ResponseMessageType[] rmta = responseMessages.Items;
        int folderNumber = 0;
        foreach (ResponseMessageType rmt in rmta)
        {
            // One FindItemResponseMessageType per folder searched.
            FindItemResponseMessageType firmt = rmt as FindItemResponseMessageType;
            if (firmt.RootFolder == null)
                continue;
            FindItemParentType fipt = firmt.RootFolder;
            object obj = fipt.Item;
            // FindItem contains an array of items.
            if (obj is ArrayOfRealItemsType)
            {
                ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType);
                if (items.Items == null)
                    folderNumber++;
                else
                {
                    foreach (ItemType it in items.Items)
                    {
                        if (it is CalendarItemType)
                        {
                            CalendarItemType cal = (CalendarItemType)it;
                            ExtendedPropertyType[] extendedProperties = GetExtendedProperties(cal.ItemId, esb);
                            if (extendedProperties != null)
                                tmp.Add(new ExtendedAppointmentData()
                                {
                                    EndDate = cal.End.ToLocalTime(),
                                    StartDate = cal.Start.ToLocalTime(),
                                    EventID = extendedProperties[0].Item.ToString(),
                                    AppointmentStatus = cal.LegacyFreeBusyStatus.ToString(),
                                    BoardroomID = boardRoomID,
                                    FreeBusyInfo = this.GetFreeBusyTimes2010(30, mailbox, startDate, endDate, esb)
                                });
                        }
                    }
                    folderNumber++;
                }
            }
        }
        return tmp;
    }
    catch
    {
        throw;
    }
}
/// <summary>
/// Gets the extended properties of a resource / boardroom.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="serviceBinding">The exchange service binding.</param>
/// <returns>
/// returns an array of extended properties; otherwise null if none existed
/// </returns>
private ExtendedPropertyType[] GetExtendedProperties(ItemIdType itemID, ExchangeServiceBinding serviceBinding)
{
    PathToExtendedFieldType pathClassification = new PathToExtendedFieldType();
    pathClassification.DistinguishedPropertySetId = DistinguishedPropertySetType.PublicStrings;
    pathClassification.DistinguishedPropertySetIdSpecified = true;
    pathClassification.PropertyName = STR_Guid;
    pathClassification.PropertyType = MapiPropertyTypeType.String;

    GetItemType getExPropertiesRequest = new GetItemType();
    ItemIdType iiItemId = new ItemIdType();
    iiItemId = itemID;
    ItemResponseShapeType getResponseShape = new ItemResponseShapeType();
    getResponseShape.BaseShape = DefaultShapeNamesType.AllProperties;
    getResponseShape.IncludeMimeContent = true;
    getExPropertiesRequest.ItemShape = getResponseShape;
    getExPropertiesRequest.ItemShape.AdditionalProperties = new BasePathToElementType[1];
    getExPropertiesRequest.ItemShape.AdditionalProperties[0] = pathClassification;

    getExPropertiesRequest.ItemIds = new ItemIdType[1];
    getExPropertiesRequest.ItemIds[0] = iiItemId;
    getExPropertiesRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
    GetItemResponseType giResponse = serviceBinding.GetItem(getExPropertiesRequest);
    if (giResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
    {
        return null;
    }
    else
    {
        ItemInfoResponseMessageType rmResponseMessage = giResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
        MessageType message = rmResponseMessage.Items.Items[0] as MessageType;               
        //return (message.ExtendedProperty);
        return (rmResponseMessage.Items.Items[0].ExtendedProperty);
    }
}


Kind regards,
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900