搜索具有上次修改时间的 EWS 日历项目

发布于 2024-08-22 08:46:53 字数 202 浏览 4 评论 0原文

我正在使用 Exchange Web 服务搜索CalendarItems。在 MSDN 文档中,有一个名为 LastModifiedTime 的字段。

如何使用 Exchange Server 绑定按 LastModifiedTime 查询 CalendarItems

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白昼 2024-08-29 08:46:53

我找到了一种使用限制的方法

(但是通过搜索
如果 findItemRequest 对象的
findItemRequest.Item
findItemRequest.Restrictions 属性已定义
它给出组合错误...)

如果仅为 findItemRequest 对象定义了 Item 或 Restrictions,则它可以工作

        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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文