MAPIFolder.Delete() - Unable to delete this folder

R

RichW

I am using the Office XP PIA to programmatically work with OOM. One
of the things I want to do is clean a messagestore of any top level
folders aside from the user "Mailbox -" hierarchy and the Public
Folders.

If I am in Outlook I can right-click on the folder and select Close
<Folder name>. It looked like I could accomplish the same thing with
MAPIFolder.Delete(). However, when I attempt to do this the following
exception is raised:

"Unable to delete this folder. Right-click the folder, and then click
Properties to check your permissions for the folder. See the folder
owner or your administrator to change your permissions."

Does anyone have any wisdom to offer on this?

Here is the code snippet:

private string CleanFolders(Microsoft.Office.Interop.Outlook.NameSpace
oNS)
{
// This method will delet any folders that have been mistakenl left
from prior jobs.
try
{
foreach (Microsoft.Office.Interop.Outlook.MAPIFolder oneStore in
oNS.Folders)
{
string FolderName = oneStore.Name;

if (FolderName == "Public Folders" ||
String.Compare(FolderName.Substring(0,10), "Mailbox - ") == 0)
continue;
else
oneStore.Delete();
}
}
catch (System.Exception ex)
{
return "Error going through Cleanfolders: " + ex.Message;
}

return "Success";

}

Best,

- Rich
 
R

RichW

I finally figured this out. I'll post it here for anyone who may be interested:

Replace the statement:
mFolder.Delete();

With:
oNS.RemoveStore(mFolder);

Best,

- Rich
 
R

RichW

I finally figured this out. I'll post it here for anyone who may be interested:

Replace the statement:
mFolder.Delete();

With:
oNS.RemoveStore(mFolder);

Best,

- Rich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top