English 中文(简体)
Search EWS CalendarItems with last modified time
原标题:

I m searching for CalendarItems with Exchange Web Services. In the documentation on MSDN there is a field named LastModifiedTime.

How do I query CalendarItems by LastModifiedTime with Exchange Server Bindings?

最佳回答

I found out a way with using restictions

(but by searching If findItemRequest object s findItemRequest.Item findItemRequest.Restictions properties are defined It gives combination error...)

If only Item or Restictions is defined for findItemRequest object it works

        List<CalendarInfo> calendarEvents = new List<CalendarInfo>();

        ExchangeServiceBinding esb = EWS.Helper.ExchangeHelper.GetExchangeBinding(credentials);

        // Form the FindItem request.
        FindItemType findItemRequest = new FindItemType();


        CalendarViewType calendarView = new CalendarViewType();
        calendarView.StartDate = criteria.StartDateAndTime;
        calendarView.EndDate = criteria.EndDateAndTime;

        if (criteria.MaxItemsToReturn > 0)
        {
            calendarView.MaxEntriesReturned = criteria.MaxItemsToReturn;
            calendarView.MaxEntriesReturnedSpecified = true;
        }

        findItemRequest.Item = calendarView;

        //--
        PathToExtendedFieldType sySyncProp = new PathToExtendedFieldType();



        sySyncProp.PropertyTag = "0x3008";
        sySyncProp.PropertyType = MapiPropertyTypeType.SystemTime;
        // Define restrictions

        RestrictionType ffRestriction = new RestrictionType();
        IsGreaterThanOrEqualToType ieGreater = new IsGreaterThanOrEqualToType();

        ieGreater.FieldURIOrConstant =  new FieldURIOrConstantType();
        ieGreater.FieldURIOrConstant.Item = new ConstantValueType();
        (ieGreater.FieldURIOrConstant.Item as ConstantValueType).Value = DateTime.Now.AddDays(-1).ToUniversalTime().ToString("u");
        ieGreater.Item = sySyncProp;

        ffRestriction.Item = ieGreater;

       findItemRequest.Restriction = ffRestriction;

        //--
        // Define which item properties are returned in the response.
        ItemResponseShapeType itemProperties = new ItemResponseShapeType();

        // Use the Default shape for the response. 
        itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
        //insert last modified time value also to responses
        PathToExtendedFieldType[] ptufta = new PathToExtendedFieldType[1];
        ptufta[0] = new PathToExtendedFieldType();
        ptufta[0].PropertyTag = "0x3008"; //Property Tag for LastModifiedTime 
        ptufta[0].PropertyType = MapiPropertyTypeType.SystemTime;
        itemProperties.AdditionalProperties = ptufta;

        findItemRequest.ItemShape = itemProperties;

        DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
        folderIDArray[0] = new DistinguishedFolderIdType();
        folderIDArray[0].Id = DistinguishedFolderIdNameType.calendar;

        if (!string.IsNullOrEmpty(criteria.EmailAddress))
        {
            folderIDArray[0].Mailbox = new EmailAddressType();
            folderIDArray[0].Mailbox.EmailAddress = criteria.EmailAddress.Trim();
        }

        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)
                    {
                        // Console.WriteLine("Folder {0}: No items in folder", folderNumber);
                        folderNumber++;
                    }
                    else
                    {
                        CalendarInfo ce;
                        CalendarItemType cal;
                        foreach (ItemType it in items.Items)
                        {

                            if (it is CalendarItemType)
                            {
                                cal = (CalendarItemType)it;
                                ce = GetCalendarInfo(esb, cal);
                                calendarEvents.Add(ce);
                            }
                            //Console.WriteLine("Folder {0}: Item identifier: {1}", folderNumber, it.ItemId.Id);

                        }

                        folderNumber++;
                    }
                }
            }

            //Console.ReadLine();
        }
        catch (Exception e)
        {
            throw;
        }


        return calendarEvents;
问题回答

暂无回答




相关问题
Java Checking number months

I think I figure out what question I am trying to ask I dont want get(Calendar.MONTH) I want the month not to be greater than the last caldendar month that is why i am doing month -1, i realize that ...

How to show custom events to a Kronolith calendar

I want to show events from an external source in the Kronolith calendar views. I don t want to do this by exporting the events to iCal and then showing them as an external calendar. The events are ...

How to reset a field when changing a date ui.datepicker.js

I m using ui.datepicker.js I have a form and when the date is changed I want that another field reset the status (this field is a dropdown select box). The case is the following: The user enter the ...

Calendar returns wrong month [duplicate]

Calendar rightNow = Calendar.getInstance(); String month = String.valueOf(rightNow.get(Calendar.MONTH)); After the execution of the above snippet, month gets a value of 10 instead of 11. How come?

How to determine if date/time is EDT or EST in Java?

I have a PDF that users must complete. The PDF has date and time fields on it. The PDF instructs the users to input the date and time in Eastern format (Not EST or EDT). When the user completes the ...

热门标签