【问题标题】: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."当我尝试通过 EWS 托管 API 读取/更新任务的 .Body 时出错 - “您必须先加载或分配此属性,然后才能读取其值。”
【发布时间】:2011-03-19 06:20:09
【问题描述】:

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

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

我使用的代码如下所示:

   //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 之类的。

那么,我需要将对象重新加载为 Item 类型吗?或者通过 .Bind 或其他方式重新加载它?请记住,我需要对数千个项目执行此操作,因此效率对我来说很重要。

【问题讨论】:

    标签: exchange-server exchangewebservices ews-managed-api


    【解决方案1】:

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

    foreach (Item item in findResults.Items)
            {                
                item.Load();
                string subject = item.Subject;
                string mailMessage = item.Body;
            }
    

    【讨论】:

    • 这应该是答案
    【解决方案2】:

    我在使用 EWS 时遇到了同样的问题。我的代码正在向

    请求事件(约会)

    Outlook 日历,最后我无法访问事件本身的正文。

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

    在收集同样源自 EWS 项目类的约会后,我做了以下事情:

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

    List<Item> items = new List<Item>();
    

    2- 将所有约会添加到项目列表中:

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

    3-使用交换服务“我已经创建并使用过”:

    oExchangeService.LoadPropertiesForItems(items, PropertySet.FirstClassProperties);
    

    现在如果你尝试使用app.Body.Text,它会成功返回。

    享受编码和好运

    我忘了提到资源:

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

    他提到了使用 Linq 来节省中间步骤,这将帮助你避免使用 List 项并节省一些内存!

    洛克人X

    【讨论】:

      【解决方案3】:

      您可以使用自定义属性集加载属性。一些属性是扩展属性而不是 FirstClassProperties。

      小例子:

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

      【讨论】:

        猜你喜欢
        • 2015-11-25
        • 2019-10-24
        • 2019-04-02
        • 2019-08-05
        • 2016-12-05
        • 1970-01-01
        • 1970-01-01
        • 2014-07-13
        • 1970-01-01
        相关资源
        最近更新 更多