简体   繁体   中英

Remove categories in outlook

I need to remove some categories.

account.DeliveryStore.Categories.Remove(n);

I try remove by index, CategoryID or name, but it very rarely works. (3 or 4 try) No errors, no exceptions, nothing. It just ignoring that command.

First, you need to get a single instance of the Categories class:

 Outlook.Categories categories = account.DeliveryStore.Categories;

And then you can deal with the categories object.

Be aware, the number of items is decreased when the category is removed from the list. So, by calling the Remove method you get the number of items decreased. You may run into the out of bounds exception if try to increase the index after.

Also I'd recommend releasing underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about that in the Systematically Releasing Objects article.

I don't know how, but it works:

account.DeliveryStore. Session .Categories.Remove(n);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM