当我尝试通过EWS托管API读取/更新任务的.Body时出错 - "您必须先加载或分配此属性,然后才能读取其值."

tgo*_*sch 34 exchange-server exchangewebservices ews-managed-api

我正在使用Exchange Web服务托管API来处理任务(Exchange 2007 SP1).我可以创造它们.但是,当我尝试进行更新时,它适用于除.Body字段之外的所有字段.每当我尝试访问(读取/更新)该字段时,它都会出现以下错误:

"You must load or assign this property before you can read its value."
Run Code Online (Sandbox Code Playgroud)

我使用的代码如下所示:

   //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
Run Code Online (Sandbox Code Playgroud)

奇怪的是,检查属性包显示该对象包含33个属性,但{Body}不是其中之一.该属性似乎是从基类.Item或其他东西继承而来的.

那么,我是否需要将对象重新加载为类型Item?或者通过.Bind或其他东西重装?请记住,我需要使用数千个项目来完成此操作,因此效率对我来说很重要.

小智 52

调用Load方法解决了我的问题:)

foreach (Item item in findResults.Items)
        {                
            item.Load();
            string subject = item.Subject;
            string mailMessage = item.Body;
        }
Run Code Online (Sandbox Code Playgroud)


小智 39

使用EWS时遇到了同样的问题.我的代码正在请求事件(约会)

Outlook日历,最后我无法触及事件本身.

在我的情况中缺少的点是"如果有任何拼写错误,请原谅我":

在收集了也来自EWS项目类的约会之后,我做了以下事情:

1-创建类型为Item的列表:

List<Item> items = new List<Item>();
Run Code Online (Sandbox Code Playgroud)

2-添加了项目列表的所有约会:

if(oAppointmentList.Items.Count > 0) // Prevent the exception
{
    foreach( Appointment app in oAppointmentList)
    {
        items.Add(app);
    }
}
Run Code Online (Sandbox Code Playgroud)

3-使用已交换的服务"我已创建并使用":

oExchangeService.LoadPropertiesForItems(items, PropertySet.FirstClassProperties);
Run Code Online (Sandbox Code Playgroud)

现在,如果您尝试使用app.Body.Text,它将成功返回.

享受编码和最佳运气

我忘了提到资源:

http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/ce1e0527-e2db-490d-817e-83f586fb1b44

他提到使用Linq来保存中间步骤,它会帮助你避免使用List项目并节省一些内存!

RockmanX


eL-*_*ova 5

您可以使用自定义属性集加载属性.某些属性是Extended属性而不是FirstClassProperties.

小例子:

        _customPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.MyResponseType, AppointmentSchema.IsMeeting, AppointmentSchema.ICalUid);
        _customPropertySet.RequestedBodyType = BodyType.Text;
        appointment.Load(_customPropertySet);