Search code examples
c#outlookoutlook-addinpst

How to remove Deleted items folder from Outlook PST file


enter image description here

Hi, I have created one PST file using C# code. My Sample code is here.

string pstlocation = @"C:\Users\{USER}\Desktop\PST Files\Test.pst";
Outlook._Application OutlookObject = this.Application;
Outlook.NameSpace outlookNs = null;
Outlook.Folder objRootFolder = null;
outlookNs = Application.GetNamespace("MAPI");    

outlookNs.AddStore(pstlocation);
objRootFolder = outlookNs.Folders.GetLast() as Folder;    

My PST file is Added successfully in outlook 2013. When i am try to delete Deleted Items but it is not deleted and it give us an error.

foreach (Folder objFolder in objRootFolder.Folders)
    {
            objFolder.Delete();
           //It gives an error.
    }

Error : An exception of type 'System.Runtime.InteropServices.COMException' occurred in OutlookAddInPSTTest.dll but was not handled in user code

Additional information: 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.

===================================================================

So, how can i delete Deleted Items from PST file.


Solution

  • By default, you cannot delete the Special folders used by Outlook. There are a couple of MS Exchange utilities/clients that will allow it, however; Outlook will recreate them upon startup.

    Reference: Microsoft Support- Cannot delete default Outlook folders

    • Inbox
    • Drafts
    • Sent Items
    • Deleted Items