c# - Unable to fetch built in properties of email along with the extended property -
i working exchange web services managed api. adding single extended property mail items in inbox processed based on condition. thus, not mails extended property attached them.
next refetching mails in inbox , if have property attached them, process them again.
below simple method getallmailsininbox()
, have written refetch mails in inbox:
class myclass { private static guid isprocessedpropertysetid; private static extendedpropertydefinition isprocessedpropertydefinition = null; static myclass() { isprocessedpropertysetid = new guid("{20f3c09f-7cad-44c6-bdbf-8fcb324244}"); isprocessedpropertydefinition = new extendedpropertydefinition(isprocessedpropertysetid, "isitemprocessed", mapipropertytype.string); } public list<emailmessage> getallmailsininbox() { list<emailmessage> emails = new list<emailmessage>(); itemview itemview = new itemview(100, 0); finditemsresults<item> itemresults = null; propertyset pspropset = new propertyset(basepropertyset.idonly); itemview.propertyset = pspropset; propertyset ititempropset = new propertyset(basepropertyset.idonly, itemschema.attachments, itemschema.subject, itemschema.importance, itemschema.datetimereceived, itemschema.datetimesent, itemschema.itemclass, itemschema.size, itemschema.sensitivity, emailmessageschema.from, emailmessageschema.ccrecipients, emailmessageschema.torecipients, emailmessageschema.internetmessageid, itemschema.mimecontent, isprocessedpropertydefinition); //*** itemresults = service.finditems(wellknownfoldername.inbox, itemview); service.loadpropertiesforitems(itemresults.items, ititempropset); string subject = ititem.subject; //exception: "you must load or assign property before can read value." //.... } }
as can see, on call service.loadpropertiesforitems()
, not load properties, resulting in you must load or assign property before can read value.
exception while accessing of properties.
if remove isprocessedpropertydefinition
ititempropset
property set, fetches properties properly.
so can know how can fetch built in emailmessage properties along extended property?
your guid 2 digits short after last dash. strange you're not seeing formatexception. still, should update code inspect getitemresponse each item. way if error occurs on 1 item, code can aware of it. means you'll need make collection return.
update code this:
serviceresponsecollection<serviceresponse> responses = service.loadpropertiesforitems(itemresults.items, ititempropset); foreach (serviceresponse response in responses) { if (response.result == serviceresult.error) { // handle error associated } else { string subject = (response getitemresponse).item.subject; } }
Comments
Post a Comment