當(dāng)前位置:
首頁(yè) >
EWS API 2.0读取日历信息-读取内容注意事项
發(fā)布時(shí)間:2025/4/14
45
豆豆
生活随笔
收集整理的這篇文章主要介紹了
EWS API 2.0读取日历信息-读取内容注意事项
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
采用模擬賬號(hào)的方式讀取日歷信息,注意下日歷的內(nèi)容讀取(Body)讀取。代碼如下:(采用 EWS API 2.0版本)
1、讀取內(nèi)容前必須設(shè)置如下屬性:否則會(huì)提示:You must load or assign this property before you can read its value? Body
如下圖:
//*************************以為設(shè)置為讀取內(nèi)容,否則會(huì)提示:You must load or assign this property before you can read its value Body PropertySet detailedPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.Recurrence); service.LoadPropertiesForItems(from Item item in findResults select item, detailedPropertySet); //******************************設(shè)置后正常。
2、如果想讀取內(nèi)容的純文本,目前Exchange server2010內(nèi)的版本支持讀取帶HTML的內(nèi)容。調(diào)用代碼如下:
//如果文本不為空 if (item.TextBody != null) { TextBody txtBody = item.TextBody; // info.BodyText = txtBody.Text; }?
調(diào)用后出現(xiàn)如下錯(cuò)誤:
所以只能用正則表達(dá)式獲取文本內(nèi)容。
?
附帶正確代碼:
#region//讀入日歷信息 /// <summary> /// 讀入日歷信息 /// </summary> /// <param name="config">配置參數(shù)</param> /// <param name="searchdtStart">開(kāi)始時(shí)間</param> /// <param name="searchdtEnd">結(jié)束時(shí)間</param> /// <returns>返回列表</returns> private static List<CalendarInfo> GetCalendarList(EwsConfig config,DateTime searchdtStart,DateTime searchdtEnd) { //返回值 List<CalendarInfo> CalendarInfoList = new List<CalendarInfo>(); try { //讀取未讀郵件 CalendarFolder calendarfolder = (CalendarFolder)Folder.Bind(service, WellKnownFolderName.Calendar); //如果不為空 if (calendarfolder != null) { //檢索開(kāi)始時(shí)間和結(jié)束時(shí)間 CalendarView calendarView = new CalendarView(searchdtStart, searchdtEnd); //檢索數(shù)據(jù) FindItemsResults<Appointment> findResults = calendarfolder.FindAppointments(calendarView); //*************************以為設(shè)置為讀取內(nèi)容,否則會(huì)提示:You must load or assign this property before you can read its value Body PropertySet detailedPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.Recurrence); service.LoadPropertiesForItems(from Item item in findResults select item, detailedPropertySet); //****************************** //返回 foreach (Appointment item in findResults.Items) { //實(shí)體類(lèi) CalendarInfo info = new CalendarInfo(); //主題 info.Identity = item.ICalUid; //來(lái)源 info.Source = "Exchange2010"; //主題 info.Subject = item.Subject; //地區(qū) info.Location = item.Location; //開(kāi)始時(shí)間 info.StartTime = item.Start.ToLocalTime(); //結(jié)束時(shí)間 info.EndTime = item.End.ToLocalTime(); //url info.Url = item.WebClientReadFormQueryString; //加入如下,表示讀取內(nèi)容,否則會(huì)提示如下: //HTML如果不為空 if (item.Body != null) { //html格式的內(nèi)容 MessageBody body = item.Body; //讀取文本 info.BodyHtml = body.Text; } // //讀取id if (item.Id != null) { info.ItemIdType = new CalendarInfo.CalendarItemIdType { Id = item.Id.UniqueId, ChangeKey = item.Id.ChangeKey }; } //加入到集合中去 CalendarInfoList.Add(info); } } } catch (Microsoft.Exchange.WebServices.Data.ServiceResponseException ex) { throw ex; } //return return CalendarInfoList; } #endregion轉(zhuǎn)載于:https://www.cnblogs.com/love007/p/3156852.html
總結(jié)
以上是生活随笔為你收集整理的EWS API 2.0读取日历信息-读取内容注意事项的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: windows下 apache 二级域名
- 下一篇: 【Bootloader】探究bootlo