采用模拟账号的方式读取日历信息,注意下日历的内容读取(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;
                        }

 

调用后出现如下错误:

所以只能用正则表达式获取文本内容。

 

附带正确代码:

 #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

EWS API 2.0读取日历信息-读取内容注意事项的更多相关文章

  1. (弃)解读Openstack Identity API v2.0

    目前OpenStack社区提供了详尽的API文档,并配有丰富的说明和示例,关于Identity API v2查看这里, 关于Identity API v3请查看这里. 尽管现在官方已经不建议OpenS ...

  2. HTML5的File API读取文件信息

    html结构: <div id="fileImage"></div> <input type="file" value=" ...

  3. ASP.NET Core的配置(1):读取配置信息

    提到"配置"二字,我想绝大部分.NET开发人员脑海中会立马浮现出两个特殊文件的身影,那就是我们再熟悉不过的app.config和web.config,多年以来我们已经习惯了将结构化 ...

  4. JPEG图片扩展信息读取与修改

    extends:http://www.2cto.com/kf/201405/303813.html 读写均是键值对的方式,需要注意的是值的类型需要严格按照api定义格式. 支持读写节点为: 1.TAG ...

  5. JPEG图片扩展信息读取与改动

    近日项目中须要用到往jpg图片中写入信息(非水印),经调研发现Android中已经封装了读写jpg图片扩展信息的api(ExifInterface). 相应api地址:http://developer ...

  6. JPEG图像扩展信息读取和修改

    最近,项目需要使用jpg图像信息被写入(非水印),经过研究发现,Android已封装的读者jpg图片扩展信息api(ExifInterface). 通讯api住址:http://developer.a ...

  7. Mp3文件标签信息读取和写入(Kotlin)

    原文:Mp3文件标签信息读取和写入(Kotlin) - Stars-One的杂货小窝 最近准备抽空完善了自己的星之小说下载器(JavaFx应用 ),发现下载下来的mp3文件没有对应的标签 也是了解可以 ...

  8. 解惑:NFC手机如何轻松读取银行卡信息?

    自支付宝钱包8.0推出了NFC新功能,只要将支持NFC功能的手机靠近公交卡.银行卡等带有芯片的IC卡上,可迅速读取卡内余额.卡的信息,还可以给卡进行充值,非常贴心实用. 但是很多网友表示担忧,要是别人 ...

  9. ios读取通讯录信息

    ios读取通讯录信息 (2012-05-22 14:07:11) 标签: ios读取通讯录 it   iphone如许app读取通讯录信息,读取通讯录信息时需要加载AddressBookUI 和Add ...

随机推荐

  1. spring源码分析之spring jmx

    JMX架构定义: https://docs.oracle.com/javase/8/docs/technotes/guides/jmx/overview/architecture.html Archi ...

  2. SWFUpload简介及中文参考手册(share)

    SWFUpload SWFUpload 版本 2 概览 (Overview) 入门( Getting Started) js对象 (SWFUpload JavaScript Object) 构造器(C ...

  3. [Python] urllib2.HTTPError: HTTP Error 403: Forbidden

    搬运自http://www.2cto.com/kf/201309/242273.html,感谢原作. 之所以出现上面的异常,是因为如果用 urllib.request.urlopen 方式打开一个UR ...

  4. 实用js代码大全

    实用js代码大全 //过滤数字 <input type=text onkeypress="return event.keyCode>=48&&event.keyC ...

  5. Theano入门神经网络(四)

    这一部分主要介绍用Theano 实现softmax函数. 在多分类任务中经常用到softmax函数,首先上几个投影片解释一下 假设目标输出是y_hat ,激活函数后的Relu y 一个是1.2 一个是 ...

  6. .NET平台下开源框架

    一.AOP框架Encase 是C#编写开发的为.NET平台提供的AOP框架.Encase 独特的提供了把方面(aspects)部署到运行时代码,而其它AOP框架依赖配置文件的方式.这种部署方面(asp ...

  7. Date对象之应用技巧

    new Date(2014,4,15);设置日期为2014年4月15日 var cur=new Date(); var prev=new Date(cur.setDate(cur.getDate()- ...

  8. 【转载】async & await 的前世今生(Updated)

    async 和 await 出现在C# 5.0之后,给并行编程带来了不少的方便,特别是当在MVC中的Action也变成async之后,有点开始什么都是async的味道了.但是这也给我们编程埋下了一些隐 ...

  9. foreach DataTable或Table时要略过第一行。

    昨天有续写一个练习<输入数字动态创建行(二)>http://www.cnblogs.com/insus/p/4916260.html ,最终是需要把数据存入数据库中. 在循环ASP:Tab ...

  10. Web前端:HTML~CSS~JS

    网页主要由3部分组成:结构.表现.行为.目前网页的新标准是W3C,模式是HTML.CSS.JavaScript,这是前端开发最核心的3个技术.前2个技术的最新版本分别为HTML5.CSS3.  “HT ...