Supprimer des rendez-vous et annuler des réunions à l'aide d’EWS dans ExchangeDelete appointments and cancel meetings by using EWS in Exchange

Découvrez comment supprimer des rendez-vous et des réunions à l’aide de l’API managée EWS ou EWS dans Exchange.Learn how to delete appointments and meetings by using the EWS Managed API or EWS in Exchange.

La principale différence entre les réunions et les rendez-vous réside dans la présence de participants aux réunions, mais pas aux rendez-vous. Les rendez-vous et les réunions peuvent être des instances uniques ou faire partie d'une série périodique. Cependant, les rendez-vous n'incluant ni participants, ni salles, ni ressources, ne nécessitent pas l'envoi d'un message. En interne, Exchange utilise le même objet pour les réunions et pour les rendez-vous. Pour utiliser les réunions et les rendez-vous, vous devez utiliser la classe Appointment de l'API managée EWS ou l'élément [CalendarItem](https://msdn.microsoft.com/library/Title Topic ID Project Name Writer Editor Publish Preview.aspx) d'EWS.The essential difference between meetings and appointments is that meetings have attendees, and appointments don't. Both appointments and meetings can be single instances or part of a recurring series, but because appointments don't include attendees, rooms, or resources, they do not require a message to be sent. Internally, Exchange uses the same object for both meetings and appointments. You use the EWS Managed API Appointment class or the EWS [CalendarItem](https://msdn.microsoft.com/library/Title Topic ID Project Name Writer Editor Publish Preview.aspx) element to work with meetings and appointments.

Tableau 1. Méthodes d’API managée EWS et opérations EWS pour la suppression de rendez-vous et de réunionsTable 1. EWS Managed API methods and EWS operations for deleting appointments and meetings

Méthode d'API managée EWSEWS Managed API method Opération EWSEWS Operation FonctionWhat it does
Rendez-vous. DeleteAppointment.Delete
DeleteItemDeleteItem
Supprime un rendez-vous.Deletes an appointment.
Rendez-vous. DeleteAppointment.Delete
CreateItem (élément de calendrier)CreateItem (calendar item)
Supprime une réunion.Deletes a meeting.

Notez que lorsque vous supprimez un rendez-vous à l’aide d’EWS, vous utilisez l’opération DeleteItem , mais lorsque vous supprimez une réunion, vous utilisez l’opération CreateItem .Note that when you delete an appointment by using EWS, you use the DeleteItem operation, but when you delete a meeting, you use the CreateItem operation. Cela peut sembler counterintuitive, mais vous devez créer un objet de réponse à une réunion pour envoyer des messages d’annulation de réunion aux participants.This might seem counterintuitive, but it is because you have to create a meeting response object to send meeting cancellation messages to attendees.

Supprimer un rendez-vous à l’aide de l’API managée EWSDelete an appointment by using the EWS Managed API

L’exemple de code suivant montre comment utiliser la méthode Delete pour supprimer un rendez-vous de votre dossier de calendrier, et la méthode ExchangeService. FindItems pour vérifier que le rendez-vous a été supprimé en le recherchant dans le dossier éléments supprimés.The following code example shows how to use the Delete method to delete an appointment from your calendar folder, and the ExchangeService.FindItems method to verify that the appointment was deleted by looking for it in the Deleted Items folder.

Cet exemple suppose que vous ont été authentifiés auprès d'un serveur Exchange et que vous avez acquis un ExchangeService object named service.This example assumes that you have authenticated to an Exchange server and have acquired an ExchangeService object named service. La variable locale appointmentId est un identificateur associé à un rendez-vous existant.The local variable appointmentId is an identifier associated with an existing appointment.

// Instantiate an appointment object by binding to it by using the ItemId.
// As a best practice, limit the properties returned to only the ones you need.
Appointment appointment = Appointment.Bind(service, appointmentId, new PropertySet());
// Delete the appointment. Note that the item ID will change when the item is moved to the Deleted Items folder.
appointment.Delete(DeleteMode.MoveToDeletedItems);
// Verify that the appointment has been deleted by looking for a matching subject in the Deleted Items folder's first entry.
ItemView itemView = new ItemView(1);
itemView.Traversal = ItemTraversal.Shallow;
// Just retrieve the properties you need.
itemView.PropertySet = new PropertySet(ItemSchema.Id, ItemSchema.ParentFolderId, ItemSchema.Subject);
// Note that the FindItems method results in a call to EWS.
FindItemsResults<Item> deletedItems = service.FindItems(WellKnownFolderName.DeletedItems, itemView);
Item deletedItem = deletedItems.First();
Folder parentFolder = Folder.Bind(service, deletedItem.ParentFolderId, new PropertySet(FolderSchema.DisplayName));
Console.WriteLine("The appointment " + "\"" + deletedItem.Subject + "\"" + " is now in the " + parentFolder.DisplayName + " folder.");

Cet exemple montre un moyen simple de vérifier que le rendez-vous a été supprimé, en vérifiant que l’objet du premier élément dans le dossier éléments supprimés correspond à celui du rendez-vous supprimé.This example shows a simple way to verify that the appointment was deleted, by verifying that the subject of the first item in the Deleted Items folder matches that of the deleted appointment. La manière dont vous choisissez de vérifier que votre rendez-vous a été supprimé dépend des besoins de votre application.How you choose to verify that your appointment was deleted will vary based the needs of your application.

Comme vous pouvez le constater, la suppression d’un rendez-vous est simple et à peu près ce que vous pouvez attendre.As you can see, deleting an appointment is straightforward and pretty much what you might expect. Remarque Lorsque vous créez votre étape de vérification que l’élément de rendez-vous dans le dossier éléments supprimés a un ItemId différent de celui de l’élément de rendez-vous dans le dossier de calendrier.Note when you create your verification step that the appointment item in the Deleted Items folder has a different ItemId than the appointment item in the calendar folder. L’élément est copié et supprimé au lieu d’être déplacé vers le dossier éléments supprimés.The item is copied and deleted rather than simply moved to the Deleted Items folder.

Supprimer un rendez-vous à l’aide d’EWSDelete an appointment by using EWS

Les codes XML de demande et de réponse dans les exemples suivants correspondent aux appels effectués par le code de l’API managée EWS dans Delete a appointment by using the EWS Managed API.The request and response XML in the following examples correspond to calls made by the EWS Managed API code in Delete an appointment by using the EWS Managed API. Le code XML de demande et de réponse qui vérifie que l’élément de rendez-vous se trouve dans le dossier éléments supprimés est également affiché.The request and response XML that verifies that the appointment item is in the Deleted Items folder is shown as well.

L’exemple suivant montre le code XML de demande pour l’opération DeleteItem afin de supprimer un rendez-vous.The following example shows the request XML for the DeleteItem operation to delete an appointment.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
       xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="Pacific Standard Time" />
    </t:TimeZoneContext>
  </soap:Header>
  <soap:Body>
    <m:DeleteItem DeleteType="MoveToDeletedItems" SendMeetingCancellations="SendToAllAndSaveCopy">
      <m:ItemIds>
        <t:ItemId Id="AAMkA" ChangeKey="DwAAA" />
      </m:ItemIds>
    </m:DeleteItem>
  </soap:Body>
</soap:Envelope>

L’exemple suivant montre le code XML de réponse renvoyé par l’opération DeleteItem .The following example shows the response XML that is returned by the DeleteItem operation. Les attributs ItemId et ChangeKey sont raccourcis pour des raisons de lisibilité.The ItemId and ChangeKey attributes are shortened for readability.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="800" MinorBuildNumber="5" Version="V2_6" 
 xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types" 
 xmlns="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:DeleteItemResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
  xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:DeleteItemResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
        </m:DeleteItemResponseMessage>
      </m:ResponseMessages>
    </m:DeleteItemResponse>
  </s:Body>
</s:Envelope>

L’exemple suivant montre le code XML de demande pour l’opération FindItem qui récupère le premier élément dans le dossier éléments supprimés afin de comparer l’objet de l’élément avec celui de l’objet de rendez-vous supprimé.The following example shows the request XML for the FindItem operation that retrieves the first item in the Deleted Items folder in order to compare the item's subject with that of the deleted appointment object.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages
" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="Pacific Standard Time" />
    </t:TimeZoneContext>
  </soap:Header>
  <soap:Body>
    <m:FindItem Traversal="Shallow">
      <m:ItemShape>
        <t:BaseShape>IdOnly</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI="item:ItemId" />
          <t:FieldURI FieldURI="item:ParentFolderId" />
          <t:FieldURI FieldURI="item:Subject" />
        </t:AdditionalProperties>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned="1" Offset="0" BasePoint="Beginning" />
      <m:ParentFolderIds>
        <t:DistinguishedFolderId Id="deleteditems" />
      </m:ParentFolderIds>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>

L’exemple suivant montre le code XML de réponse renvoyé par l’opération FindItem au cours de l’étape de vérification.The following example shows the response XML that is returned by the FindItem operation during the verification step.

Notes

Les attributs ItemId et ChangeKey sont raccourcis pour des raisons de lisibilité.The ItemId and ChangeKey attributes are shortened for readability.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="800" MinorBuildNumber="5" Version="V2_6" 
 xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types" 
 xmlns="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:FindItemResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:FindItemResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:RootFolder IndexedPagingOffset="1" TotalItemsInView="10748" IncludesLastItemInRange="false">
            <t:Items>
              <t:CalendarItem>
                <t:ItemId Id="AAMkA=" ChangeKey="DwAAA" />
                <t:ParentFolderId Id="AAMkA" ChangeKey="AQAAA" />
                <t:Subject>Tennis lesson</t:Subject>
              </t:CalendarItem>
            </t:Items>
          </m:RootFolder>
        </m:FindItemResponseMessage>
      </m:ResponseMessages>
    </m:FindItemResponse>
  </s:Body>
</s:Envelope>

Supprimer une réunion à l’aide de l’API managée EWSDelete a meeting by using the EWS Managed API

Lorsque vous supprimez une réunion, outre la suppression de l’élément de rendez-vous du dossier calendrier, vous pouvez également envoyer des annulations de réunion aux participants.When you delete a meeting, in addition to removing the appointment item from the calendar folder, you might also want to send meeting cancellations to attendees. Vous pouvez utiliser les trois méthodes suivantes pour annuler une réunion :You can use the following three methods to cancel a meeting:

La méthode que vous choisissez dépend du niveau de détail que vous devez fournir dans votre message d’annulation.The method that you choose depends on the level of detail you need to provide in your cancellation message. Rendez-vous. CancelMeeting facilite la mise à jour du message d’annulation en transmettant un message mis à jour en tant que paramètre.Appointment.CancelMeeting makes it easy to update the cancellation message by passing an updated message as a parameter. CancelMeetingMessage vous permet de modifier les propriétés de votre message avant d’envoyer une annulation, afin que vous puissiez effectuer des actions comme demander un accusé de réception.CancelMeetingMessage allows you to modify properties on your message before sending a cancellation, so you can do things like request a receipt.

Les exemples de code de cette section présentent les différentes façons de supprimer une réunion et d’envoyer des annulations de réunion.The code examples in this section show the different ways to delete a meeting and send meeting cancellations. Les exemples partent du principe que vous avez été authentifié auprès d’un serveur Exchange et que vous avez acquis un objet ExchangeService nommé service.The examples assume that you have authenticated to an Exchange server and have acquired an ExchangeService object named service. La variable locale meetingId est un identificateur associé à une réunion existante où l’utilisateur cible est l’organisateur de la réunion.The local variable meetingId is an identifier associated with an existing meeting where the target user is the meeting organizer.

L’exemple de code suivant montre comment supprimer une réunion à l’aide de la méthode appointment . Delete .The following code example shows how to delete a meeting by using the Appointment.Delete method.

// Instantiate an appointment object for the meeting by binding to it using the ItemId.
// As a best practice, limit the properties returned to only the Appointment ID.
            
Appointment meeting = Appointment.Bind(service, meetingId, new PropertySet());
// Delete the meeting by using the Delete method.
meeting.Delete(DeleteMode.MoveToDeletedItems, SendCancellationsMode.SendToAllAndSaveCopy);
// Verify that the meeting has been deleted by looking for a matching subject in the Deleted Items folder's first entry.
ItemView itemView = new ItemView(1);
itemView.Traversal = ItemTraversal.Shallow;
// Just retrieve the properties you need.
itemView.PropertySet = new PropertySet(ItemSchema.Id, ItemSchema.ParentFolderId, ItemSchema.Subject);
// Note that the FindItems method results in a call to EWS.
FindItemsResults<Item> deletedItems = service.FindItems(WellKnownFolderName.DeletedItems, itemView);
Item deletedItem = deletedItems.First();
Folder parentFolder = Folder.Bind(service, deletedItem.ParentFolderId, new PropertySet(FolderSchema.DisplayName));
Console.WriteLine("The meeting " + "\"" + deletedItem.Subject + "\"" + " is now in the " + parentFolder.DisplayName + " folder.");

L’exemple de code suivant montre comment supprimer une réunion à l’aide de la méthode CancelMeeting .The following code example shows how to delete a meeting by using the CancelMeeting method.

// Instantiate an appointment object by binding to it using the ItemId.
// As a best practice, limit the properties returned to only the Appointment ID.
Appointment meeting = Appointment.Bind(service, meetingId, new PropertySet());
// Delete the meeting by using the CancelMeeting method.
meeting.CancelMeeting("The outdoor meeting has been cancelled due to hailstorms.");

L’exemple de code suivant montre comment supprimer une réunion à l’aide de la méthode appointment . CreateCancelMeetingMessage .The following code example shows how to delete a meeting by using the Appointment.CreateCancelMeetingMessage method.

// Instantiate an appointment object by binding to it using the ItemId.
// As a best practice, limit the properties returned to only the Appointment ID.
Appointment meeting = Appointment.Bind(service, meetingId, new PropertySet());
// Delete the meeting by using the CreateCancelMeetingMessage method.
CancelMeetingMessage cancelMessage = meeting.CreateCancelMeetingMessage();
cancelMessage.Body = new MessageBody("The outdoor meeting has been canceled due to hailstorms.");
cancelMessage.IsReadReceiptRequested = true;
cancelMessage.SendAndSaveCopy();

Supprimer une réunion à l’aide d’EWSDelete a meeting by using EWS

Les codes XML de demande et de réponse dans les exemples suivants correspondent aux appels effectués par le code de l’API managée EWS dans Delete a Meeting using the EWS Managed API by using the appointment . Delete , méthode.The request and response XML in the following examples correspond to calls made by the EWS Managed API code in Delete a meeting by using the EWS Managed API by using the Appointment.Delete method.

L’exemple suivant montre le code XML de requête lorsque vous utilisez l’opération CreateItem pour envoyer des messages d’annulation aux participants et supprimer une réunion.The following example shows the request XML when you use the CreateItem operation to send cancellation messages to attendees and delete a meeting.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
       xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="Pacific Standard Time" />
    </t:TimeZoneContext>
  </soap:Header>
  <soap:Body>
    <m:CreateItem MessageDisposition="SendAndSaveCopy">
      <m:Items>
        <t:CancelCalendarItem>
          <t:ReferenceItemId Id="AAMkA" ChangeKey="DwAAA" />
          <t:NewBodyContent BodyType="HTML">The outdoor meeting has been canceled due to hailstorms.</t:NewBodyContent>
        </t:CancelCalendarItem>
      </m:Items>
    </m:CreateItem>
  </soap:Body>
</soap:Envelope>

L’exemple suivant montre le code XML renvoyé en réponse à une demande d’opération CreateItem utilisée pour supprimer une réunion.The following example shows the XML that is returned in response to a CreateItem operation request used to delete a meeting.

Notes

Les attributs ItemId et ChangeKey sont raccourcis pour des raisons de lisibilité.The ItemId and ChangeKey attributes are shortened for readability.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="800" MinorBuildNumber="5" Version="V2_6" 
 xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types" 
 xmlns="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:CreateItemResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:CreateItemResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:Items>
            <t:CalendarItem>
              <t:ItemId Id="AAMkA" ChangeKey="DwAAA" />
            </t:CalendarItem>
          </m:Items>
        </m:CreateItemResponseMessage>
      </m:ResponseMessages>
    </m:CreateItemResponse>
  </s:Body>
</s:Envelope>

L’exemple suivant montre le code XML de demande pour l’opération FindItem qui récupère le premier élément dans le dossier éléments supprimés afin de comparer l’objet de l’élément avec celui de l’objet de rendez-vous supprimé.The following example shows the request XML for the FindItem operation that retrieves the first item in the Deleted Items folder in order to compare the item's subject with that of the deleted appointment object.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
       xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="Pacific Standard Time" />
    </t:TimeZoneContext>
  </soap:Header>
  <soap:Body>
    <m:FindItem Traversal="Shallow">
      <m:ItemShape>
        <t:BaseShape>IdOnly</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI="item:ItemId" />
          <t:FieldURI FieldURI="item:ParentFolderId" />
          <t:FieldURI FieldURI="item:Subject" />
        </t:AdditionalProperties>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned="1" Offset="0" BasePoint="Beginning" />
      <m:ParentFolderIds>
        <t:DistinguishedFolderId Id="deleteditems" />
      </m:ParentFolderIds>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>

L’exemple suivant montre le code XML renvoyé par l’opération FindItem au cours de l’étape de vérification.The following example shows the XML that is returned by the FindItem operation during the verification step.

Notes

Les attributs ID et ChangeKey sont raccourcis pour des raisons de lisibilité.The Id and ChangeKey attributes are shortened for readability.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="800" MinorBuildNumber="5" Version="V2_6" 
 xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types" 
 xmlns="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:FindItemResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:FindItemResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:RootFolder IndexedPagingOffset="1" TotalItemsInView="10750" IncludesLastItemInRange="false">
            <t:Items>
              <t:CalendarItem>
                <t:ItemId Id="AAMkA" ChangeKey="DwAAA" />
                <t:ParentFolderId Id="AAMkA" ChangeKey="AQAAA" />
                <t:Subject>Team building exercise</t:Subject>
              </t:CalendarItem>
            </t:Items>
          </m:RootFolder>
        </m:FindItemResponseMessage>
      </m:ResponseMessages>
    </m:FindItemResponse>
  </s:Body>
</s:Envelope>

Voir aussiSee also