For Each ... Next VB.NET 2010 and Outlook 2010 problem

Hi experts,
Im writting little application for recursive move content of outlook folders to another. Nothing difficult.

Im using VS 2010 (Visual Basic) and Office 2010. All fully patched.

My code is easy for example:

Private Sub WipeRecurse(RootFolder As Folder, DstFolder As Folder)
        Dim cnt As ContactItem

       For Each cnt in RootFolder.Items
            cnt.Move(DstFolder)
        Next


        Dim sf As Folder

        For Each sf in RootFolder.Folders
            WipeRecurse(sf, DstFolder)
        Loop

        If RootFolder.FolderPath <> ComboBox2.SelectedItem Then
            RootFolder.Delete()
        End If

    End Sub

Open in new window


Last contact or folder in each parent folder is not handled... Scary? please can you try it?

Is there any hotfix for that?

Following code is working as expected:

    Private Sub WipeRecurse(RootFolder As Folder, DstFolder As Folder)
        Dim cnt As ContactItem

        Do Until RootFolder.Items.Count = 0
            cnt = RootFolder.Items(RootFolder.Items.Count)
            cnt.Move(DstFolder)

        Loop


        Dim sf As Folder

        Do Until RootFolder.Folders.Count = 0
            sf = RootFolder.Folders.Item(RootFolder.Folders.Count)
            WipeRecurse(sf, DstFolder)
        Loop

        If RootFolder.FolderPath <> ComboBox2.SelectedItem Then
            RootFolder.Delete()
        End If

    End Sub

Open in new window

LVL 6
Jan Vojtech VanicekIT SpecialistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul JacksonSoftware EngineerCommented:
Hmm interesting, try changing to as below to see if that makes any difference :

Private Sub WipeRecurse(RootFolder As Folder, DstFolder As Folder)

       For Each cnt As ContactItem in RootFolder.Items
            cnt.Move(DstFolder)
        Next

        For Each sf As Folder in RootFolder.Folders
            WipeRecurse(sf, DstFolder)
        Loop

        If RootFolder.FolderPath <> ComboBox2.SelectedItem Then
            RootFolder.Delete()
        End If

    End Sub 

Open in new window


If that doesn't solve it, when running through in debug can you examine the Items collection or the Folders collection returned and see if what you expect to be returned is returned by the collection.
0
Jan Vojtech VanicekIT SpecialistAuthor Commented:
I hase moved that code from Outlook to EWS... Office interops are not well done...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jan Vojtech VanicekIT SpecialistAuthor Commented:
Interops are simply crap...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.