EWS API 2.0讀取行事曆資訊-讀取內容注意事項

來源:互聯網
上載者:User

標籤:c   style   class   blog   code   java   

[from] http://www.cnblogs.com/love007/archive/2013/06/26/3156852.html

採用類比帳號的方式讀取行事曆資訊,注意下日曆的內容讀取(Body)讀取。代碼如下:(採用 EWS API 2.0版本)

1、讀取內容前必須設定如下屬性:否則會提示:You must load or assign this property before you can read its value  Body

如下:

 

 //*************************以為設定為讀取內容,否則會提示: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);

 

 //******************************

 

設定後正常。

 

2、如果想讀取內容的純文字,目前Exchange server2010內的版本支援讀取帶HTML的內容。調用代碼如下:

 

 //如果文本不為空白

 

                        if (item.TextBody != null)

 

                        {

 

                            TextBody txtBody = item.TextBody;

 

                            //

 

                            info.BodyText = txtBody.Text;

 

                        }

 

 

 

調用後出現如下錯誤:

 

所以只能用Regex擷取常值內容。 

 

附帶正確代碼:

 

#region//讀入行事曆資訊        /// <summary>        /// 讀入行事曆資訊        /// </summary>        /// <param name="config">配置參數</param>        /// <param name="searchdtStart">開始時間</param>        /// <param name="searchdtEnd">結束時間</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)                {                    //檢索開始時間和結束時間                    CalendarView calendarView = new CalendarView(searchdtStart, searchdtEnd);                    //檢索資料                    FindItemsResults<Appointment> findResults = calendarfolder.FindAppointments(calendarView);                    //*************************以為設定為讀取內容,否則會提示: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)                    {                                                //實體類                        CalendarInfo info = new CalendarInfo();                        //主題                        info.Identity = item.ICalUid;                        //來源                        info.Source = "Exchange2010";                        //主題                        info.Subject = item.Subject;                        //地區                        info.Location = item.Location;                        //開始時間                        info.StartTime = item.Start.ToLocalTime();                        //結束時間                        info.EndTime = item.End.ToLocalTime();                        //url                        info.Url = item.WebClientReadFormQueryString;                        //加入如下,表示讀取內容,否則會提示如下:                                               //HTML如果不為空白                        if (item.Body != null)                        {                            //html格式的內容                            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

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.