2
\$\begingroup\$

I would like to know if there's a more efficient way of querying items than this (that works, though):

Imports Microsoft.Exchange.WebServices

Public Class ExchangeTools
    Private Shared Function Items(
                                 target_folder As Data.Folder,
                                 Optional recurse As Boolean = False,
                                 Optional querystring As String = Nothing
                                 ) As IEnumerable(Of Data.EmailMessage)
        Dim retvar As IEnumerable(Of Data.EmailMessage)
        Dim iview = New Data.ItemView(Integer.MaxValue)
        If String.IsNullOrWhiteSpace(querystring) Then
            retvar = target_folder.FindItems(iview).OfType(Of Data.EmailMessage)
        Else
            retvar = target_folder.FindItems(querystring, iview).OfType(Of Data.EmailMessage)
        End If
        If recurse Then
            Dim fview = New Data.FolderView(Integer.MaxValue)
            retvar = retvar.Concat(
                target_folder.FindFolders(fview).SelectMany(
                    Function(sf) Items(sf, True, querystring)))
        End If
        Return retvar
    End Function
End Class
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.