Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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."

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 

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.

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.

like image 700
tgolisch Avatar asked Jul 21 '10 21:07

tgolisch


People also ask

What is EWS API?

Exchange Web Services (EWS) is an application program interface (API) that allows programmers to access Microsoft Exchange items such as calendars, contacts and email.

Is the EWS API deprecated?

Today we are announcing the deprecation of the 25 least used APIs of EWS for Exchange Online (as determined by the call volume into the service). We are retiring these APIs to begin the process of reducing the surface area of the EWS protocol for maintenance and security purposes.


1 Answers

Calling the Load method solved my problem :)

foreach (Item item in findResults.Items)         {                             item.Load();             string subject = item.Subject;             string mailMessage = item.Body;         } 
like image 121
hasianjana Avatar answered Oct 05 '22 12:10

hasianjana