How do I delete Search folders?

  • Thread starter Thread starter Mark B
  • Start date Start date
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)
{
}
}
}
 
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.
 
Back
Top