문제

I am facing a strange problem - all the Outlook folders are not being deleted.

 using OL = Microsoft.Office.Interop.Outlook;

 OL.NameSpace olNamespace = Globals.ThisAddIn.Application.GetNamespace("MAPI");
 OL.MAPIFolder olInboxFolder = olNamespace.Session.GetDefaultFolder(OL.OlDefaultFolders.olFolderInbox);

 foreach (OL .MAPIFolder folder in olInboxFolder .Folders)
 {
      folder.Delete();
 }

The above code deletes 4 out of the 7 folders. All the folders are empty, and the delete operation is being performed on the same PST.

도움이 되었습니까?

해결책

Wghen yo udelete folders, you change the number of items in the collection. Do not use the foreach loops if you delete the items. Use a down for loop:

for (int i = olInboxFolder.Folders.Count; i >= 1; i--)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top