如何通过 uniqueId 预约 EWS
How to get appointment with EWS by uniqueId
我使用 EWS 创建约会没有问题。我这样保存 uniqueId
Dim rdvEncours As DevisRdv = GetRdv(ConnectedUser,LesDatas)
Appointment.Save(New FolderId(WellKnownFolderName.Calendar, rdvEncours.Collaborateur.Mail))
rdvEncours.ExchangeId = Appointment.Id.UniqueId
LesDatas.SaveChange();
之后我想删除它。我有一个基于标题、日期、小时的工作函数,但它并不完全安全。然后我想使用我的 UniqueId
然后我创建这个函数
Public Function FindAppointment(Service As ExchangeService, UnikId As String) As Appointment
Dim CalendarFolder As CalendarFolder = CalendarFolder.Bind(Service, New FolderId(WellKnownFolderName.Calendar, ml), New PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount))
' Set the number of items to the smaller of the number of items in the Contacts folder Or 1000.
Dim numItems As Integer = If(CalendarFolder.TotalCount < 1000, CalendarFolder.TotalCount, 1000)
' Instantiate the item view with the number of items to retrieve from the contacts folder.
' To keep the request smaller, send only the display name.
Dim View As ItemView = New ItemView(numItems) With {.PropertySet = New PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.End, AppointmentSchema.Start)}
' Create a searchfilter to check the subject of the tasks.
Dim searchFilter As SearchFilter.SearchFilterCollection = New SearchFilter.SearchFilterCollection From {New SearchFilter.IsEqualTo(ItemSchema.Id, UnikId)}
' Retrieve the items in the Calendar folder with the properties you selected.
Dim taskItems = Service.FindItems(New FolderId(WellKnownFolderName.Calendar, ml), searchFilter, View)
If taskItems.Count = 1 AndAlso TypeOf taskItems.Items(0) Is Appointment Then
Return taskItems.Items(0)
HelperJournal.WriteEntry("Find Rdv by id") 'TODO:A mettre ne commentaire quand vérifier
Else
Return Nothing
End If
End Function
我这样称呼它
Dim FoundTask As Appointment = FindAppointment(ConnectToExchange(), rdvEncours.ExchangeId)
If (FoundTask IsNot Nothing) Then FoundTask.Delete(DeleteMode.HardDelete)
但是 FindAppointment 发生错误
Message:La valeur spécifiée est non valide pour la propriété.
Exception:Microsoft.Exchange.WebServices.Data.ServiceResponseException: La valeur spécifiée est non valide pour la propriété.
à Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()
à Microsoft.Exchange.WebServices.Data.ServiceResponse.ThrowIfNecessary()
à Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest1.Execute()
à Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems[TItem](IEnumerable
1 parentFolderIds, SearchFilter searchFilter, String queryString, ViewBase view, Grouping groupBy, ServiceErrorHandling errorHandlingMode)
à Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems(FolderId parentFolderId, SearchFilter searchFilter, ViewBase view)
à Maximus.HelperAgenda.FindAppointment(ExchangeService Service, String UnikId) dans XXX\HelperAgenda.vb:ligne 50
à Maximus.VisuDevis.PoseInter(SetDevisRDV MesDonnees) dans XXX\VisuDevis.aspx.vb:ligne 560
Info Supplémentaire :Suppression RDV dans calendrier
如果您有 ItemId,那么您可以直接绑定到日历项,实际的 属性 不可搜索,因此无法在 findItems 中使用。但只需使用
Appointment aptItem = Appointment.Bind(service, ItemId);
也就是说,存储和绑定到 Itemid 可能会有问题,请参阅 https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/ews-identifiers-in-exchange,因为这些 itemId 可以更改。
格伦 2020 年 4 月 6 日的评论是正确的回应
这里是摘要
Dim Appointment As New Appointment(service) With {
.Subject = "MySubject",
.Start = rdvEncours.DteInter,
.Body = "MyBody",
.Importance = Importance.High
}
Appointment.End = Appointment.Start.AddHours(1)
Dim MaClef As String = getRandomString(256)
Appointment.SetExtendedProperty(GetCustomKeyAppointment, MaClef)
Appointment.Save(New FolderId(WellKnownFolderName.Calendar, rdvEncours.Collaborateur.Mail))
rdvEncours.ExchangeId = MaClef
LesDatas.SaveChanges()
而且,就像您需要为您的新自定义密钥提供一个参考一样,在我
的一个模块中
' Get the GUID for the property set.
Private Const MyCustomKeySetId As String = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
Public Function GetCustomKeyAppointment() As ExtendedPropertyDefinition
Return New ExtendedPropertyDefinition(New Guid(MyCustomKeySetId), "Mykey", MapiPropertyType.String)
End Function
并找到您的约会
Public Function FindAppointment(Service As ExchangeService, UnikId As String) As Appointment
Dim CalendarFolder As CalendarFolder = CalendarFolder.Bind(Service, New FolderId(WellKnownFolderName.Calendar, ml), New PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount))
' Set the number of items to the smaller of the number of items in the Contacts folder Or 1000.
Dim numItems As Integer = If(CalendarFolder.TotalCount < 1000, CalendarFolder.TotalCount, 1000)
' Instantiate the item view with the number of items to retrieve from the contacts folder.
' To keep the request smaller, send only the display name.
Dim View As ItemView = New ItemView(numItems) With {.PropertySet = New PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.End, AppointmentSchema.Start)}
' Create a searchfilter to check the subject of the tasks.
Dim searchFilter As SearchFilter = New SearchFilter.IsEqualTo(GetCustomKeyAppointment, UnikId)
' Retrieve the items in the Calendar folder with the properties you selected.
Dim taskItems = Service.FindItems(New FolderId(WellKnownFolderName.Calendar, ml), searchFilter, View)
If taskItems.Count = 1 AndAlso TypeOf taskItems.Items(0) Is Appointment Then
Return taskItems.Items(0)
Else
Return Nothing
End If
End Function
我使用 EWS 创建约会没有问题。我这样保存 uniqueId
Dim rdvEncours As DevisRdv = GetRdv(ConnectedUser,LesDatas)
Appointment.Save(New FolderId(WellKnownFolderName.Calendar, rdvEncours.Collaborateur.Mail))
rdvEncours.ExchangeId = Appointment.Id.UniqueId
LesDatas.SaveChange();
之后我想删除它。我有一个基于标题、日期、小时的工作函数,但它并不完全安全。然后我想使用我的 UniqueId 然后我创建这个函数
Public Function FindAppointment(Service As ExchangeService, UnikId As String) As Appointment
Dim CalendarFolder As CalendarFolder = CalendarFolder.Bind(Service, New FolderId(WellKnownFolderName.Calendar, ml), New PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount))
' Set the number of items to the smaller of the number of items in the Contacts folder Or 1000.
Dim numItems As Integer = If(CalendarFolder.TotalCount < 1000, CalendarFolder.TotalCount, 1000)
' Instantiate the item view with the number of items to retrieve from the contacts folder.
' To keep the request smaller, send only the display name.
Dim View As ItemView = New ItemView(numItems) With {.PropertySet = New PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.End, AppointmentSchema.Start)}
' Create a searchfilter to check the subject of the tasks.
Dim searchFilter As SearchFilter.SearchFilterCollection = New SearchFilter.SearchFilterCollection From {New SearchFilter.IsEqualTo(ItemSchema.Id, UnikId)}
' Retrieve the items in the Calendar folder with the properties you selected.
Dim taskItems = Service.FindItems(New FolderId(WellKnownFolderName.Calendar, ml), searchFilter, View)
If taskItems.Count = 1 AndAlso TypeOf taskItems.Items(0) Is Appointment Then
Return taskItems.Items(0)
HelperJournal.WriteEntry("Find Rdv by id") 'TODO:A mettre ne commentaire quand vérifier
Else
Return Nothing
End If
End Function
我这样称呼它
Dim FoundTask As Appointment = FindAppointment(ConnectToExchange(), rdvEncours.ExchangeId)
If (FoundTask IsNot Nothing) Then FoundTask.Delete(DeleteMode.HardDelete)
但是 FindAppointment 发生错误
Message:La valeur spécifiée est non valide pour la propriété. Exception:Microsoft.Exchange.WebServices.Data.ServiceResponseException: La valeur spécifiée est non valide pour la propriété. à Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary() à Microsoft.Exchange.WebServices.Data.ServiceResponse.ThrowIfNecessary() à Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest
1.Execute() à Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems[TItem](IEnumerable
1 parentFolderIds, SearchFilter searchFilter, String queryString, ViewBase view, Grouping groupBy, ServiceErrorHandling errorHandlingMode) à Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems(FolderId parentFolderId, SearchFilter searchFilter, ViewBase view) à Maximus.HelperAgenda.FindAppointment(ExchangeService Service, String UnikId) dans XXX\HelperAgenda.vb:ligne 50 à Maximus.VisuDevis.PoseInter(SetDevisRDV MesDonnees) dans XXX\VisuDevis.aspx.vb:ligne 560 Info Supplémentaire :Suppression RDV dans calendrier
如果您有 ItemId,那么您可以直接绑定到日历项,实际的 属性 不可搜索,因此无法在 findItems 中使用。但只需使用
Appointment aptItem = Appointment.Bind(service, ItemId);
也就是说,存储和绑定到 Itemid 可能会有问题,请参阅 https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/ews-identifiers-in-exchange,因为这些 itemId 可以更改。
格伦 2020 年 4 月 6 日的评论是正确的回应 这里是摘要
Dim Appointment As New Appointment(service) With {
.Subject = "MySubject",
.Start = rdvEncours.DteInter,
.Body = "MyBody",
.Importance = Importance.High
}
Appointment.End = Appointment.Start.AddHours(1)
Dim MaClef As String = getRandomString(256)
Appointment.SetExtendedProperty(GetCustomKeyAppointment, MaClef)
Appointment.Save(New FolderId(WellKnownFolderName.Calendar, rdvEncours.Collaborateur.Mail))
rdvEncours.ExchangeId = MaClef
LesDatas.SaveChanges()
而且,就像您需要为您的新自定义密钥提供一个参考一样,在我
的一个模块中 ' Get the GUID for the property set.
Private Const MyCustomKeySetId As String = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
Public Function GetCustomKeyAppointment() As ExtendedPropertyDefinition
Return New ExtendedPropertyDefinition(New Guid(MyCustomKeySetId), "Mykey", MapiPropertyType.String)
End Function
并找到您的约会
Public Function FindAppointment(Service As ExchangeService, UnikId As String) As Appointment
Dim CalendarFolder As CalendarFolder = CalendarFolder.Bind(Service, New FolderId(WellKnownFolderName.Calendar, ml), New PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount))
' Set the number of items to the smaller of the number of items in the Contacts folder Or 1000.
Dim numItems As Integer = If(CalendarFolder.TotalCount < 1000, CalendarFolder.TotalCount, 1000)
' Instantiate the item view with the number of items to retrieve from the contacts folder.
' To keep the request smaller, send only the display name.
Dim View As ItemView = New ItemView(numItems) With {.PropertySet = New PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.End, AppointmentSchema.Start)}
' Create a searchfilter to check the subject of the tasks.
Dim searchFilter As SearchFilter = New SearchFilter.IsEqualTo(GetCustomKeyAppointment, UnikId)
' Retrieve the items in the Calendar folder with the properties you selected.
Dim taskItems = Service.FindItems(New FolderId(WellKnownFolderName.Calendar, ml), searchFilter, View)
If taskItems.Count = 1 AndAlso TypeOf taskItems.Items(0) Is Appointment Then
Return taskItems.Items(0)
Else
Return Nothing
End If
End Function