Free Support Forum - aspose.com

How to delete a message folder inside PST file

Hi,
I would like some help on deleting an empty message folder from a PST file.
Thanks

@kelberuc1
Thank you for your request. You can delete a folder from a PST file using Aspose.Email as follows:

// C#
FolderInfo folderInfo = personalStorage.RootFolder.GetSubFolder("folder_name");
personalStorage.RootFolder.DeleteChildItem(folderInfo.EntryId);

API Reference: FolderInfo.DeleteChildItem Method

// Java
FolderInfo folderInfo = personalStorage.getRootFolder().getSubFolder("folder_name");
personalStorage.getRootFolder().deleteChildItem(folderInfo.getEntryId());

API Reference: FolderInfo.deleteChildItem method

1 Like

@Andrey_Potapov,

After deleting the folder according to your instructions, Microsoft Outlook still shows it when I open the PST file, but now it displays the error screen attached below…

screen1.png (43.4 KB)

What can I do to solve this?

Thanks

@kelberuc1,
Could you share your code snippet and a PST file sample that can be used for investigating the problem, please? Also, please specify the version of Aspose.Email which you use.

@Andrey_Potapov,

I found an issue in my code when deleting folders, it seems OK now using your example.
If I need anything else, I will let you know.

Thank you very much for your help!

@kelberuc1
Sure, I am glad you found the cause of this problem.