当我尝试通过EWS托管API读取/更新任务的主体时出现错误-“必须先加载或分配此属性,然后才能读取其值." [英] Error when I try to read/update the .Body of a Task via EWS Managed API - "You must load or assign this property before you can read its value."
问题描述
我正在使用Exchange Web Services托管API来处理任务(Exchange 2007 SP1).我可以创建它们.但是,当我尝试进行更新时,它适用于除.Body字段以外的所有字段.每当我尝试访问(读取/更新)该字段时,都会出现以下错误:
I am using the Exchange Web Services Managed API to work with Tasks (Exchange 2007 SP1). I can create them fine. However, when I try to do updates, it works for all of the fields except for the .Body field. Whenever I try to access (read/update) that field, it gives the following error:
"You must load or assign this property before you can read its value."
我正在使用的代码如下:
The code I am using looks like this:
//impersonate the person whose tasks you want to read
Me.Impersonate(userName); //home-made function to handle impersonation
//build the search filter
Exchange.SearchFilter.SearchFilterCollection filter = New Exchange.SearchFilter.SearchFilterCollection();
filter.Add(New Exchange.SearchFilter.IsEqualTo(Exchange.TaskSchema.Categories, "Sales"));
//do the search
EWS.Task exTask = esb.FindItems(Exchange.WellKnownFolderName.Tasks, filter, New Exchange.ItemView(Integer.MaxValue));
exTask.Subject = txtSubject.Text; //this works fine
exTask.Body = txtBody.Text; //This one gives the error implying that the object isn't loaded
奇怪的是,检查属性包显示该对象包含33个属性,但是{Body}不是其中之一.该属性似乎是从基类.Item继承的.
The strange thing is that, inspecting the property bag shows that the object contains 33 properties, but {Body} is not one of them. That property seems to be inherited from the base class .Item, or something.
那么,我是否需要将对象重新加载为Item类型?还是通过.Bind或其他方式重新加载?请记住,我需要处理数千个项目,因此效率对我来说很重要.
So, do I need to re-load the object as type Item? Or reload it via .Bind or something? Keep in mind that I need to do this with thousands of items, so efficiency does matter to me.
推荐答案
在使用EWS时,我遇到了同样的问题.我的代码正在从
I had the same problem when using the EWS. My Code is requesting the events(Appointments) from the
Outlook日历,最后我无法触及活动本身.
Outlook calendar, at the end I couldn't reach to the body of the Event itself.
我这种情况的缺失点是以下如果有任何拼写错误,请原谅我":
The missing point in my situation was the following "forgive me if there is any typo errors":
在收集了也从EWS Item类派生的约会之后,我执行了以下操作:
After gathering the Appointments, which are also derived from EWS Item Class, I did the following:
1-创建一个类型为Item的列表:
1- Create a List with the type Item:
List<Item> items = new List<Item>();
2-将所有约会添加到项目列表中:
2- Added all appointments to items list:
if(oAppointmentList.Items.Count > 0) // Prevent the exception
{
foreach( Appointment app in oAppointmentList)
{
items.Add(app);
}
}
3-使用了交换的服务我已经创建并使用":
3- Used the exchanged service "I have already created and used":
oExchangeService.LoadPropertiesForItems(items, PropertySet.FirstClassProperties);
现在,如果您尝试使用app.Body.Text,它将成功返回它.
now if you try to use app.Body.Text, it will return it successfully.
享受编码和好运
我忘了提及资源了:
他提到使用Linq保存中间步骤,这将帮助您避免使用List项目并节省一些内存!
He mentioned the use of Linq to save the intermediate step, it will help you avoid using the List items and save some memory!
RockmanX
这篇关于当我尝试通过EWS托管API读取/更新任务的主体时出现错误-“必须先加载或分配此属性,然后才能读取其值."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!