none
Remove a Public Folder Favortie RRS feed

  • Question

  • I see that I can use AddToPFFavorites() but is there any way to loop PF Favorites, get one to delete it, change its name or properties?

    Wednesday, May 2, 2012 8:01 PM

Answers

  • Thanks Dmitry.  I'm not sure if this is because I'm using VS2010 & Outlook 2010, but I can't find a olPublicFoldersFavorites constant anywhere.

    I don't know if this is the best way, but I got there with the following code:

    Outlook.Folder AllPublicFolder = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders) as Outlook.Folder;
                    Outlook.Folder RootPublicFolder = AllPublicFolder.Parent;
                    Outlook.Folders RootPublicSubFolders = RootPublicFolder.Folders;
    
                    bool blnPFFavoritesContactsFound = false;
                    bool blnPFFavoritesTasksFound = false;
                   
                    foreach (Outlook.Folder rootPubSub in RootPublicSubFolders)
                    {
                        if (rootPubSub.Name == "Favorites")
                        {
                            foreach (Outlook.MAPIFolder PublicFavorite in rootPubSub.Folders)
                            {
                                if (PublicFavorite.EntryID == Properties.Settings.Default.PFLegalContactsEntryID)
                                {
                                    blnPFFavoritesContactsFound = true;                               
                                }
    
                                if (PublicFavorite.EntryID == Properties.Settings.Default.PFLegalTasksEntryID)
                                {
                                    blnPFFavoritesTasksFound = true;                                
                                }
                            }
                        }
                    }

    • Marked as answer by Nerds Thursday, May 3, 2012 2:52 PM
    Thursday, May 3, 2012 2:31 PM

All replies

  • Retrieve the Favorites folder usign GetDefaultFolder(olPublicFoldersFavorites), then loop through its children (MAPIFolder.Folders).

    Unfortunately OOM does not allows removing a folder from PF favorites - there is a MAPIFolder.AddToPFFavorites method, but there is no corresponding RemoveFromPFFavorites (Redemption does expose that method).

    

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Wednesday, May 2, 2012 9:06 PM
  • Thanks Dmitry.  I'm not sure if this is because I'm using VS2010 & Outlook 2010, but I can't find a olPublicFoldersFavorites constant anywhere.

    I don't know if this is the best way, but I got there with the following code:

    Outlook.Folder AllPublicFolder = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders) as Outlook.Folder;
                    Outlook.Folder RootPublicFolder = AllPublicFolder.Parent;
                    Outlook.Folders RootPublicSubFolders = RootPublicFolder.Folders;
    
                    bool blnPFFavoritesContactsFound = false;
                    bool blnPFFavoritesTasksFound = false;
                   
                    foreach (Outlook.Folder rootPubSub in RootPublicSubFolders)
                    {
                        if (rootPubSub.Name == "Favorites")
                        {
                            foreach (Outlook.MAPIFolder PublicFavorite in rootPubSub.Folders)
                            {
                                if (PublicFavorite.EntryID == Properties.Settings.Default.PFLegalContactsEntryID)
                                {
                                    blnPFFavoritesContactsFound = true;                               
                                }
    
                                if (PublicFavorite.EntryID == Properties.Settings.Default.PFLegalTasksEntryID)
                                {
                                    blnPFFavoritesTasksFound = true;                                
                                }
                            }
                        }
                    }

    • Marked as answer by Nerds Thursday, May 3, 2012 2:52 PM
    Thursday, May 3, 2012 2:31 PM
  • Sorry, Outlook only defines olDefaultFolders.olPublicFoldersAllPublicFolders, Redemption also adds olPublicFoldersFavorites.
    
    

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Thursday, May 3, 2012 3:04 PM