gpt4 book ai didi

calendar - 使用上次修改时间搜索 EWS CalendarItems

转载 作者:行者123 更新时间:2023-12-02 00:41:51 25 4
gpt4 key购买 nike

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

如何使用 Exchange Server 绑定(bind)通过 LastModifiedTime 查询 CalendarItems

最佳答案

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

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

如果只为 findItemRequest 对象定义了 Item 或 Resctions,它就可以工作

        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;

关于calendar - 使用上次修改时间搜索 EWS CalendarItems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2297412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com