我使用Independentsoft.Pst从pst文件中提取约会,但问题是for循环遍历文件的整个约会,这需要花费一些时间在非常大的文件中。如果有人可以通过无循环或将Independentsoft.Pst itemCollection转换为数组的方式向我展示一种方法,我将非常高兴。
我的代码:
Public Function getAppointment(ByVal file As String) As List(Of String)
Dim AppointmentDetails As New List(Of String)
Dim App As New List(Of ItemCollection)
Dim calendar As Folder
Dim PSTfile = New PstFile(file)
Dim delta As TimeSpan = MonthCalendar1.SelectionEnd - MonthCalendar1.SelectionStart
Dim DelResult As Integer = delta.Duration.Days
Using PSTfile
calendar = PSTfile.MailboxRoot.GetFolder("calendar")
If calendar IsNot Nothing Then
Dim items As ItemCollection = calendar.GetItems()
For m As Integer = 0 To items.Count - 1
If TypeOf items(m) Is Appointment Then
Dim appointment As Appointment = DirectCast(items(m), Appointment)
AppointmentDetails.Add(appointment.Subject)
AppointmentDetails.Add(appointment.CreationTime)
AppointmentDetails.Add(appointment.CreationTime.Date)
AppointmentDetails.Add(appointment.Duration)
End If
Next
End If
End Using
Return AppointmentDetails
End Function
答案 0 :(得分:0)
您的意思是根据其中一个属性的特定值找到约会。 这是使用PIA的一些代码。
Private Shared Function GetAppointmentsFolder() As Outlook.MAPIFolder
Dim result As Outlook.MAPIFolder = Nothing
If OutlookApp.ActiveExplorer.CurrentFolder.DefaultItemType = Outlook.OlItemType.olAppointmentItem Then
result = OutlookApp.ActiveExplorer.CurrentFolder
End If
If result Is Nothing Then
result = OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
End If
Return result
End Function
Public Function GetAppointment(billingInfo as string) As Outlook.AppointmentItem
Dim appointmentsFolder As Outlook.MAPIFolder = GetAppointmentsFolder()
'Try to find an existing appointment (Using Find() Locates and returns an Outlook item object that satisfies the given Filter..)
Dim outlookAppointmentItem As Outlook.AppointmentItem = CType(appointmentsFolder.Items.Find("BillingInformation]=""" & pstrAppointmentId & """"), Outlook.AppointmentItem)
Return outlookAppointmentItem
End Function