【问题标题】:How to get appointment with EWS by uniqueId如何通过 uniqueId 预约 EWS
【发布时间】:2020-03-31 10:04:48
【问题描述】:

我使用 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 出现错误

消息:La valeur spécifiée est non valide pour la propriété。 例外: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](IEnumerable1 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 Supplementaire :Suppression RDV dans calendrier

【问题讨论】:

    标签: vb.net exchangewebservices appointment


    【解决方案1】:

    如果您有 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 可以更改。

    【讨论】:

    • 感谢您的回复。第一:商店和召回我的约会之间没有修改(测试帐户上大约 10 秒)第二我认为过滤器上的错误更多。存储changeId并重新生成itemId是否更好?我读过所有人都只存储 uniqueId?
    • 您将无法根据唯一 ID 进行搜索 (Fitler),Exchange 存储不允许这样做,因为它是多余的(例如,如果可以的话,您有 Id 绑定它) t 绑定到它,那么您拥有的 Id 不再有效)。如果你想要一个 ID,你可以搜索我建议 PidTagSearchKey docs.microsoft.com/en-us/office/client-developer/outlook/mapi/… 或创建你自己的自定义属性和值。
    • 哦...我不知道。有一个关于 PidTagSearchKey 或自定义属性的简单示例。从存储到在过滤器中使用?不好意思问。但我没有要测试的 Exchange 服务器。我需要部署在真实的服务器中,看看它是否好,然后如果我可以从一个好的基础开始......
    【解决方案2】:

    2020 年 4 月 6 日的 Glen cmets 是正确的回应 这里是总结

     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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-09
      • 1970-01-01
      相关资源
      最近更新 更多