Recursive/traversal search of items using EWS managed API in subfolders too

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












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






share|improve this question



























    up vote
    2
    down vote

    favorite












    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






    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      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






      share|improve this question













      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








      share|improve this question












      share|improve this question




      share|improve this question








      edited Apr 28 at 0:32









      Jamal♦

      30.1k11114225




      30.1k11114225









      asked Apr 27 at 23:48









      VBobCat

      1656




      1656

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f193121%2frecursive-traversal-search-of-items-using-ews-managed-api-in-subfolders-too%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f193121%2frecursive-traversal-search-of-items-using-ews-managed-api-in-subfolders-too%23new-answer', 'question_page');

          );

          Post as a guest













































































          Q q4FVJUcI4MV1LK
          xLxo8y,yY,Ike2kZy,vFXCkMedeIr

          Popular posts from this blog

          Chat program with C++ and SFML

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          Python - Quiz Game with Tkinter