通过EWS API预约获取Body [英] Get the Body from an appointment with the EWS API

查看:97
本文介绍了通过EWS API预约获取Body的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


编写了一些代码,将分发组中每个用户的整个日历导出为ics文件。


我的问题是我无法在ics文件中导出/写入约会的正文。我得到:


"您必须先加载或分配此属性,然后才能读取其值。"


如果我在搜索每个日历文件夹后绑定每个约会以获得
正文生成ics文件需要几个小时。


这是我的代码:

 //实例化ExchangeService类+ Exchange证书验证+模仿
ServicePointManager .ServerCertificateValidationCallback = CertificateValidationCallBack;
ExchangeService服务=新的ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Credentials = new NetworkCredential(" user"," password"," domain");
service.AutodiscoverUrl(" impersonator @ domain",RedirectionUrlValidationCallback);

//区分分配组
string distributiongroup =" distribution @ domain" ;;

//初始化开始和结束时间的值。
DateTime startDate = DateTime.Now.AddDays(-10);
DateTime endDate = startDate.AddDays(180);

//扩展通讯组
ExpandGroupResults distGroupMembers = service.ExpandGroup(distributiongroup);
foreach(distGroupMembers.Members中的EmailAddress地址)
{
//模拟每个通讯组成员
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress,address.Address);

//创建iCalendar并添加本地时区
iCalendar iCal = new iCalendar();
ITimeZone localTZ = iCal.AddLocalTimeZone();

//构建其他时区列表(已包含本地时区)
列表< ITimeZone> otherTimeZones = new List< ITimeZone>();
foreach(TimeZoneInfo tzi in System.TimeZoneInfo.GetSystemTimeZones())
{
if(tzi!= System.TimeZoneInfo.Local)
{
//添加我们列表的时区(但不要直接包含在日历中)。
otherTimeZones.Add(iCalTimeZone.FromSystemTimeZone(tzi));
}
}

// ics文件的路径和文件名
string icsFileDirectory = @" C:\\Users \\ikyriakidis \ \Desktop\\ICAL\\英寸;
string icsFileName1 = address.Address;
string icsFileName2 =" .ics" ;;
string icsFileName = icsFileName1 + icsFileName2;
string icsFile = Path.Combine(icsFileDirectory,icsFileName);


//设置会议/活动提醒(事件发生前5分钟)
报警闹钟=新报警();
alarm.Action = AlarmAction.Display;
alarm.Trigger = new Trigger(TimeSpan.FromMinutes(-05));


//在日历文件夹中执行搜索并返回视图
CalendarView cView = new CalendarView(startDate,endDate);
cView.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
FindItemsResults<约会> apt = service.FindAppointments(WellKnownFolderName.Calendar,cView);

foreach(apt中的约会应用)
{
// Appointment appDetailed = Appointment.Bind(service,app.Id,new PropertySet(BasePropertySet.FirstClassProperties){ RequestedBodyType = BodyType.Text});

//在ical
事件中创建事件iCalEvent = iCal.Create< Event>();

//设置事件papameters
iCalEvent.Summary = app.Subject;
//iCalEvent.Description = app.Subject;
iCalEvent.Description = app.Body.Text;
iCalEvent.Start = new iCalDateTime(app.Start);
iCalEvent.End = new iCalDateTime(app.End);
iCalEvent.Duration = app.Duration;
iCalEvent.Location = app.Location;
if(app.IsReminderSet == true)
{
alarm.Description =" Reminder" ;;
iCalEvent.Alarms.Add(闹钟);
}
if(app.Sensitivity == Sensitivity.Private)
{
iCalEvent.Summary =" privater Termin" ;;
iCalEvent.Description =" privater Termin" ;;
iCalEvent.Location ="英寸;
}
}



//创建ics文件
iCalendarSerializer serializer = new iCalendarSerializer(iCal);
if(!Directory.Exists(icsFileDirectory))
{
Directory.CreateDirectory(icsFileDirectory);
serializer.Serialize(icsFile);
}
else
{
serializer.Serialize(icsFile);
}


}


}

我更换了" ; iCalEvent.Description = app.Body.Text;"使用" iCalEvent.Description = app.subject; "并注释掉" Appointment appDetailed = Appointment.Bind(service,app.Id,new PropertySet(BasePropertySet.FirstClassProperties)
{RequestedBodyType = BodyType.Text});
"生成所有ics文件所需的时间不超过90秒!


你可以帮我解决这个问题吗...我已经连续几天努力工作了......


谢谢。


Ioannis



解决方案

在FindItems操作中不会返回约会(或消息)的正文
http://msdn.microsoft.com/en-us/library/bb508824(v = exchg.80).aspx  所以你需要使用GetItem来获取Body(你的ICS)同时也缺少与GetItem一起返回
的与会者。最有效的方法是使用LoadPropertiesForItems,在
预约中执行此操作的样本
http://blogs.msdn.com/b/exchangedev/archive/ 2010/03/16 /加载的属性换多的项目与 - 一个呼叫到交换网络services.aspx
功能;.这允许您批处理GetItem请求(这将比使用加载要快得多),但是你b $ b应该尝试将属性限制为仅为了性能而需要的属性。


干杯zh
Glen



Hello,

wrote some code to export the whole calendar for each user in a distribution group as an ics File.

My problem is tha I am not able to export/write the Body of the appointment in the ics file. I get:

"You must load or assign this property before you can read its value.".

If I bind every appointment after I have searched every Calendarfolder to get the Body it takes hours to generate the ics files.

Here is my code:

            //Instantiate the ExchangeService class+ Exchange Certificate Validation + Impersonator
            ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            service.Credentials = new NetworkCredential("user", "password", "domain");
            service.AutodiscoverUrl("impersonator@domain", RedirectionUrlValidationCallback);

            //Distinguish Distribution Group
            string distributiongroup = "distribution@domain";

            // Initialize values for the start and end time.
            DateTime startDate = DateTime.Now.AddDays(-10);
            DateTime endDate = startDate.AddDays(180);

            //Extend the distribution group
            ExpandGroupResults distGroupMembers = service.ExpandGroup(distributiongroup);
            foreach (EmailAddress address in distGroupMembers.Members)
            {
                //Impersonate each distribution group member
                service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, address.Address);

                //Create iCalendar and add local time zone
                iCalendar iCal = new iCalendar();
                ITimeZone localTZ = iCal.AddLocalTimeZone();

                // Build a list of additional time zones (local time zone is allready included)
                List<ITimeZone> otherTimeZones = new List<ITimeZone>();
                foreach (TimeZoneInfo tzi in System.TimeZoneInfo.GetSystemTimeZones())
                {
                    if (tzi != System.TimeZoneInfo.Local)
                    {
                        // Add the time zone to our list (but don't include it directly in the calendar).
                        otherTimeZones.Add(iCalTimeZone.FromSystemTimeZone(tzi));
                    }
                }

                //Path and Filename for ics File
                string icsFileDirectory = @"C:\\Users\\ikyriakidis\\Desktop\\ICAL\\";
                string icsFileName1 = address.Address;
                string icsFileName2 = ".ics";
                string icsFileName = icsFileName1 + icsFileName2;
                string icsFile = Path.Combine(icsFileDirectory, icsFileName);


                //Set reminder for the Meetings/Events (5 minutes befor event)
                Alarm alarm = new Alarm();
                alarm.Action = AlarmAction.Display;
                alarm.Trigger = new Trigger(TimeSpan.FromMinutes(-05));


                // Execute the search in the calendar folder and return the view
                CalendarView cView = new CalendarView(startDate, endDate);
                cView.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
                FindItemsResults<Appointment> apt = service.FindAppointments(WellKnownFolderName.Calendar, cView);

                foreach (Appointment app in apt)
                {
                    //Appointment appDetailed = Appointment.Bind(service, app.Id, new PropertySet(BasePropertySet.FirstClassProperties) { RequestedBodyType = BodyType.Text });

                    //Create event in ical
                    Event iCalEvent = iCal.Create<Event>();

                    //Set the event papameters
                    iCalEvent.Summary = app.Subject;
                    //iCalEvent.Description = app.Subject;
                    iCalEvent.Description = app.Body.Text;
                    iCalEvent.Start = new iCalDateTime(app.Start);
                    iCalEvent.End = new iCalDateTime(app.End);
                    iCalEvent.Duration = app.Duration;
                    iCalEvent.Location = app.Location;
                    if (app.IsReminderSet == true)
                    {
                        alarm.Description = "Reminder";
                        iCalEvent.Alarms.Add(alarm);
                    }
                    if (app.Sensitivity == Sensitivity.Private)
                    {
                        iCalEvent.Summary = "privater Termin";
                        iCalEvent.Description = "privater Termin";
                        iCalEvent.Location = " ";
                    }
                }



                //Create ics File
                iCalendarSerializer serializer = new iCalendarSerializer(iCal);
                if (!Directory.Exists(icsFileDirectory))
                {
                    Directory.CreateDirectory(icsFileDirectory);
                    serializer.Serialize(icsFile);
                }
                else
                {
                    serializer.Serialize(icsFile);
                }


            }


        }

Whene I replace the "iCalEvent.Description = app.Body.Text;" with "iCalEvent.Description = app.subject;" and comment out the "Appointment appDetailed = Appointment.Bind(service, app.Id, new PropertySet(BasePropertySet.FirstClassProperties) { RequestedBodyType = BodyType.Text });" it takes no more than 90 seconds to generate all the ics files!

Can you please help me on this one.. I have been strugeling for days to make it work...

Thank you.

Ioannis

解决方案

The body of an appointment (or Message) won't be returned in a FindItems Operation http://msdn.microsoft.com/en-us/library/bb508824(v=exchg.80).aspx so you need to use GetItem to get the Body (your ICS is also missing attendees which similarly will only be returned with GetItem). The most efficient way to do with is to use LoadPropertiesForItems there is a sample for doing this on appointment in http://blogs.msdn.com/b/exchangedev/archive/2010/03/16/loading-properties-for-multiple-items-with-one-call-to-exchange-web-services.aspx . This allows you to batch the GetItem request (which will be considerable faster then using load) but you should try to limit the properties to just those that you need for performance sake.

Cheers
Glen


这篇关于通过EWS API预约获取Body的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆