切换到宽版
  • 6297阅读
  • 0回复

[分享]Exchange Web Service获取日历、会议 [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2015-06-29
本文介绍如何使用EWS代理类调用Exchange的日历
(1)首先生成代理类

ExchangeServiceBinding _ExchangeBinding = new ExchangeServiceBinding();_ExchangeBinding.Credentials = new NetworkCredential(username, password, domain);_ExchangeBinding.Url = Helper.GetWebconfig("exchangewebservice");(2)定义请求的属性
  请注意:在定义请求属性时,一定要定义CalendarViewType属性,默认的日历返回是不含循环日历的,
如果需要返回循环会议请求,就需要等译CalendarView

FindItemType findItemRequest = new FindItemType();ItemResponseShapeType itemProperties = new ItemResponseShapeType();itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;findItemRequest.ItemShape = itemProperties;//我们查找的是日历      DistinguishedFolderIdType[] folderIDs = { new DistinguishedFolderIdType { Id = DistinguishedFolderIdNameType.calendar } };           findItemRequest.ParentFolderIds = folderIDs;//增加搜索的日历范围,红色代码要饭服务器返回循环会议CalendarViewType cldview = new CalendarViewType();cldview.StartDate = dt.AddDays(-2);cldview.EndDate = dt.AddDays(2);findItemRequest.Item = cldview;findItemRequest.Traversal = ItemQueryTraversalType.Shallow;(3)定义服务器返回的数据属性

   FindItemResponseType findItemResponse = _ExchangeBinding.FindItem(findItemRequest);ArrayOfResponseMessagesType responseMessages = findItemResponse.ResponseMessages;ResponseMessageType[] responseMessage = responseMessages.Items;foreach (ResponseMessageType rmt in responseMessage){#region 结果FindItemResponseMessageType msgType = (rmt as FindItemResponseMessageType);if (msgType.RootFolder == null)continue;FindItemParentType parentType = msgType.RootFolder;object obj = parentType.Item;if (obj is ArrayOfRealItemsType){ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType);if (items != null){if (items.Items != null){foreach (ItemType item in items.Items){CalendarItemType calItem = item as CalendarItemType;DataRow row = table.NewRow();row["roomid"] = 1;row["guid"] = guid;row["begintime"] = calItem.Start.AddHours(timezone);row["endtime"] = calItem.End.AddHours(timezone);row["location"] = calItem.Location;row["title"] = calItem.Subject;row["displayname"] = calItem.Organizer.Item.Name;if (row["endtime"].ToString() != ""){table.Rows.Add(row);}}}}}#endregion}
分享到
快速回复
限60 字节
 
上一个 下一个