I'm using the Outllok Interop to move emails from one folder to another (after getting all of the attachments, but that works) but it isn't copying all of the emails. I've tried putting a wait in, but it doesn't have an effect. First it'll move 6, then 3, then 1. Can anyone tell me why its not moving them all?
Relevant code is below:
Application oOutlook = new Application();
NameSpace oNs = oOutlook.GetNamespace("MAPI");
Recipient oRep = oNs.CreateRecipient("ContentHelp");
MAPIFolder inbox = oNs.GetSharedDefaultFolder(oRep, OlDefaultFolders.olFolderInbox);
MAPIFolder nihSub = inbox.Folders["NIH"];
MAPIFolder nihArchive = inbox.Folders["NIHarchive"];
Items nihItems = nihSub.Items;
MailItem moveMail = null;
//inboxItems = inboxItems.Restrict("[Unread] = false");
int increment = 0;
try
{
foreach (object collectionItem in nihItems)
{
moveMail = collectionItem as MailItem;
if (moveMail != null)
{
Console.WriteLine("Moving {0}", moveMail.Subject.ToString());
string titleSubject = (string)moveMail.Subject;
moveMail.Move(nihArchive);
}
}
}