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.
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
Calling the Load method solved my problem :)
foreach (Item item in findResults.Items)
{
item.Load();
string subject = item.Subject;
string mailMessage = item.Body;
}
You can load properties using a custom property set. Some properties are Extended properties instead of FirstClassProperties.
Little example:
_customPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.MyResponseType, AppointmentSchema.IsMeeting, AppointmentSchema.ICalUid);
_customPropertySet.RequestedBodyType = BodyType.Text;
appointment.Load(_customPropertySet);

Related Links

How to do paging with Exchange Web Services CalendarView
Exchange 2010 Journaling email content
Does an exchange server duplicate email data when a user forward it? [closed]
How can I filter out private events in a calendar query for Exchange WebDav?
Exchange Web Service vs Exchange ActiveSync (or why buy the milk when you can get the cow for free?)
Is there an easy way to implement an exchange mail server?
Catch All rule - how to catch all emails that has been sent to not existing email address
Can EWS calls be done parallel without slowing down?
Exchange transport agent to check senders of email message
Exchange Online Signature for new and replay message
EWS: copy items between mailboxes/accounts
Where can I get the latest Microsoft.Exchange.WebServices.DLL?
Exchange 2003 OWA galfind only returning HTML response
Exchange 2010 EWS cannot access 2007 MailBox - AutoDiscover?
Retrieving ALL emails for ALL accounts from exchange server
Kerio EWS differences to real Exchange EWS?

Categories

HOME
flask
magento2
android-studio
class
apple-push-notifications
jms
qc
swi-prolog
mongoid
web2py
swift2
gprs
pm2
hidden
gravity
robolectric
jaspersoft-studio
coroutine
raml
akka-persistence
neo4j.rb
ini
software-packaging
function-points
annotation-processing
macromedia
amazon-cloudtrail
fusion
docx4j
shapeless
custom-keyboard
landscape
spinner
eclipse-gmf
aurelia-http-client
netapp
cloudera-sentry
dagger
react-intl
destroy
brightscript
uiautomatorviewer
lightning-workbench
skip-lists
wikimapia
email-forwarding
dblink
kendo-treeview
pbx
pjax
bigdecimal
e
ndk-build
ftp-client
seccomp
declarative
bbc-micro
adp
currency-exchange-rates
android-expansion-files
ioexception
odesk
dsa
canopy
unhandled
embeddedwebserver
relational-model
physicsjs
mathematical-expressions
adhoc-polymorphism
siena
nachos
flipboard
property-injection
roxy-fileman
autonumber
compiler-flags
xsd2code
san
mute
revmob
iirf
coalesce
ofstream
examine
xalan
firebird1.5
uipangesturerecognizer
opends
infopath-2007
winsxs
django-pagination
hungarian-notation
fgetc
eventaggregator
eai
downcasting
accumulator
database-cloning
regioninfo

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App