C
C.Shamis
I am using VB 2005, VSTO 2005 SE BETA, Outlook 2003 SP2.
I am trying to iterate through all the item in an Outlook.MAPIFolder, and
move it to another. The problem is sometimes the assignment fails.
The problem is, the code works for hundreds of items at a time, but it may
fail on the 200th, or the 30th. There is no rhyme or reason I can detect. I
can run the program over and over with the same data-set (a *copy* of my
inbox on our exchange server), and it will fail in different places each
time.
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim objFolderItems As Outlook.Items
Dim objMail As Outlook.MailItem
objApp = CreateObject("Outlook.Application")
objNS = objApp.GetNamespace("MAPI")
objSourceFolder = objNS.GetFolderFromID(My.Settings.SourceID)
objDestFolder = objNS.GetFolderFromID(My.Settings.DestID)
objFolderItems = objSourceFolder.Items
If radMove.Checked Then
For i As Integer = objFolderItems.Count To 1 Step -1
objMail = TryCast(objFolderItems.Item(i), Outlook.MailItem)
If Not objMail Is Nothing Then
objMail.Move(objDestFolder)
End If
Next i
MsgBox(objFolderItems.Count.ToString() + " message(s) could not
be moved.")
End If
Do I need to use a different object method to assign the
objFolderItems.Item(i) into my objMail? TryCast isn't the right thing to
use? Do I need to put a "lock" on the MAPIFolder? Do I need to perform a
"wait" on the object?
--Chris
I am trying to iterate through all the item in an Outlook.MAPIFolder, and
move it to another. The problem is sometimes the assignment fails.
The problem is, the code works for hundreds of items at a time, but it may
fail on the 200th, or the 30th. There is no rhyme or reason I can detect. I
can run the program over and over with the same data-set (a *copy* of my
inbox on our exchange server), and it will fail in different places each
time.
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim objFolderItems As Outlook.Items
Dim objMail As Outlook.MailItem
objApp = CreateObject("Outlook.Application")
objNS = objApp.GetNamespace("MAPI")
objSourceFolder = objNS.GetFolderFromID(My.Settings.SourceID)
objDestFolder = objNS.GetFolderFromID(My.Settings.DestID)
objFolderItems = objSourceFolder.Items
If radMove.Checked Then
For i As Integer = objFolderItems.Count To 1 Step -1
objMail = TryCast(objFolderItems.Item(i), Outlook.MailItem)
If Not objMail Is Nothing Then
objMail.Move(objDestFolder)
End If
Next i
MsgBox(objFolderItems.Count.ToString() + " message(s) could not
be moved.")
End If
Do I need to use a different object method to assign the
objFolderItems.Item(i) into my objMail? TryCast isn't the right thing to
use? Do I need to put a "lock" on the MAPIFolder? Do I need to perform a
"wait" on the object?
--Chris