How do I delete Search folders?

M

Mark B

OL2007, VSTO

On Addin exit, I am trying to delete all search folders I previously
programmatically created so that next time OnAddin startup, I can recreate
them cleanly (in order to try and workaround unexpected behavior such as
folder italicization after 1 or 2 days).

When I walk through the code I see an exception generated at
existingFolder.Delete() stopping the delete:

"Cannot 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."

Any ideas on why this would be happening and how to remedy it?

public void Remove()
{
if (this.folderEntryId != null)
{
Outlook.Application olApp;
olApp = Globals.ThisAddIn.Application;

try
{
Outlook.MAPIFolder existingFolder =
olApp.GetNamespace("MAPI").GetFolderFromID(
this.folderEntryId, Type.Missing);

if (existingFolder != null)
existingFolder.Delete();
}
catch (Exception)
{
}
}
}
 
K

Ken Slovak - [MVP - Outlook]

Does the same code run without errors if you run it some other place in your
addin? If so try handling the Explorer.Close() event and if there are no
other Explorers and no open Inspectors then call your remove code then. See
if that works.
 

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