Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

exchange server - 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.

question from:https://stackoverflow.com/questions/3304157/error-when-i-try-to-read-update-the-body-of-a-task-via-ews-managed-api-you-m

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had the same problem when using the EWS. My Code is requesting the events(Appointments) from the

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

After gathering the Appointments, which are also derived from EWS Item Class, I did the following:

1- Create a List with the type Item:

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

2- Added all appointments to items list:

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

3- Used the exchanged service "I have already created and used":

oExchangeService.LoadPropertiesForItems(items, PropertySet.FirstClassProperties);

now if you try to use app.Body.Text, it will return it successfully.

Enjoy Coding and Best Luck

I forgot to mention the resource:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...