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

3

6

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

Gypsy answered 24/11, 2010 at 15:21 Comment(0)
H
5

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" /> 
Hildehildebrand answered 28/11, 2010 at 2:28 Comment(2)
thanks, so it is as I understand it some how, so what do I need to do to get the itemID and the ChangeKey ? after I "save" appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy); ?Gypsy
Take a look at this link - blogs.msdn.com/b/exchangedev/archive/2010/03/16/…. Keep in mind that EWS is a "web service" and that the results of soliciting the service is serialized (i.e. in XML as you requested).Hildehildebrand
L
8

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

Lamination answered 6/1, 2011 at 22:55 Comment(0)
H
5

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" /> 
Hildehildebrand answered 28/11, 2010 at 2:28 Comment(2)
thanks, so it is as I understand it some how, so what do I need to do to get the itemID and the ChangeKey ? after I "save" appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy); ?Gypsy
Take a look at this link - blogs.msdn.com/b/exchangedev/archive/2010/03/16/…. Keep in mind that EWS is a "web service" and that the results of soliciting the service is serialized (i.e. in XML as you requested).Hildehildebrand
K
0

Other way is to load the object after your action. But as it is said before, you can use the Appointment.Id.

Karate answered 23/8, 2012 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.