PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook Interoperability MAPIFolder.Delete() - Unable to delete this folder

Reply

MAPIFolder.Delete() - Unable to delete this folder

 
Thread Tools Rate Thread
Old 08-07-2004, 06:48 PM   #1
RichW
Guest
 
Posts: n/a
Default MAPIFolder.Delete() - Unable to delete this folder


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
  Reply With Quote
Old 13-07-2004, 03:49 PM   #2
RichW
Guest
 
Posts: n/a
Default Re: MAPIFolder.Delete() - Unable to delete this folder

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
  Reply With Quote
Old 13-07-2004, 03:49 PM   #3
RichW
Guest
 
Posts: n/a
Default Re: MAPIFolder.Delete() - Unable to delete this folder

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
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off