Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# create calendar item with EWS, how to get back the results?

I build an app based on this site http://msdn.microsoft.com/en-us/library/dd633661%28v=EXCHG.80%29.aspx

appointment.Subject = "Status Meeting";
appointment.Body = "The purpose of this meeting is to discuss status.";
appointment.Start = new DateTime(2009, 3, 1, 9, 0, 0);
appointment.End = appointment.Start.AddHours(2);
appointment.Location = "Conf Room";
appointment.RequiredAttendees.Add("[email protected]");
appointment.RequiredAttendees.Add("[email protected]");
appointment.OptionalAttendees.Add("[email protected]");
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);

how I can return the XML results "... < t:ItemId Id="AAMkADk=" ChangeKey="DwAAAB" /> ..." so I can use it later to delete or edit the calendar item!?!

Microsoft made a god job with the whole Framework, but did they really forgot this little thing?

I found some (not logical for me) solution Link should I use this to solve the issue?

cheers

like image 917
Data-Base Avatar asked Nov 24 '10 15:11

Data-Base


2 Answers

I could be missing the point, but after the save you can get appointment.Id which I believe is the unique id for this appointment. Store it somewhere and then later you can access the appointment again for edit or delete with:

Appointment appointment = Appointment.Bind(service, new ItemID("saved id value"));

After that you can change the values with the same properties that you used to set them originally and then issue:

appointment.Update(ConflictResolutionMode.AlwaysOverwrite);

or to delete:

appointment.Delete(DeleteMode.HardDelete);

You don't have to access the XML at all.

(n.b. As far I can tell you can't update or delete appointments from Public Folder calendars, although you can create them.)

like image 159
Tony Avatar answered Oct 24 '22 10:10

Tony


It looks like the solution you found is not returning the XMl results, persay. What the solution is doing is appending a unique identifier to the e-mail as an ExtendedPropertyDefinition. Then after sending it, the solution searches through the "Sent Items" folder to find a saved copy of the e-mail that was just sent by matching on the unique identifier that was appended before the e-mail was sent.

Then as written on the blog,

The following is the XML request that is generated by calling FindItems in the above code example.

<m:FindItem Traversal="Shallow"> 
   <m:ItemShape> 
      <t:BaseShape>IdOnly</t:BaseShape> 
      <t:AdditionalProperties> 
         <t:FieldURI FieldURI="item:Subject" /> 
         <t:ExtendedFieldURI PropertySetId="20b5c09f-7cad-44c6-bdbf-8fcbeea08544" PropertyName="MyExtendedPropertyName" PropertyType="String" /> 
      </t:AdditionalProperties> 
   </m:ItemShape> 
   <m:IndexedPageItemView MaxEntriesReturned="5" Offset="0" BasePoint="Beginning" /> 
   <m:Restriction> 
      <t:IsEqualTo> 
         <t:ExtendedFieldURI PropertySetId="20b5c09f-7cad-44c6-bdbf-8fcbeea08544" PropertyName="MyExtendedPropertyName" PropertyType="String" /> 
         <t:FieldURIOrConstant> 
            <t:Constant Value="MyExtendedPropertyValue" /> 
         </t:FieldURIOrConstant> 
      </t:IsEqualTo> 
   </m:Restriction> 
   <m:ParentFolderIds> 
      <t:DistinguishedFolderId Id="sentitems" /> 
   </m:ParentFolderIds> 
</m:FindItem>

Note the XML tag containing the unique identifier.

<t:ExtendedFieldURI PropertySetId="20b5c09f-7cad-44c6-bdbf-8fcbeea08544" PropertyName="MyExtendedPropertyName" PropertyType="String" /> 
like image 5
bitxwise Avatar answered Oct 24 '22 11:10

bitxwise