Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 547393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:58:06+00:00 2026-05-13T10:58:06+00:00

We are developing Outlook 2007 add-in. For testing outlook category renaming I’ve added the

  • 0

We are developing Outlook 2007 add-in. For testing outlook category renaming I’ve added the following code block

 var session = Application.Session;
 var categories = session.Categories;
 var category1 = session.Categories[1];

 //catefory1.Name is "Group1" before executing line below
 category1.Name = "TEST!!!";

 Marshal.ReleaseComObject(category1);
 Marshal.ReleaseComObject(categories);
 Marshal.ReleaseComObject(session);

to the end of add-in private void ThisAddIn_Startup(object sender, EventArgs e) method.
Category is renamed but if Outlook is closed, the above lines are commented, and outlook is started again – the category name is not “TEST!!!” as I expected. It is “Group1” as is was before renaming. Is it possible to rename outlook category “forever” by code? Microsoft.Office.Interop.Outlook.Category has no Save() or Update() or Persist() methods.

P.S. We are developing Outlook 2007 add-in using Visual Studio 2008, .net 3.5, C# 3.
The problem is reproduced with Outlook 2007 SP1 and SP2. Other outlook versions were not tested.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:58:06+00:00Added an answer on May 13, 2026 at 10:58 am

    I have solved the problem (the problem itself seems to be Outlook 2007 bug) using a hack.
    The following links helped me to create the hack (oops, not enough reputation to post more then 1 link):

    • http ://blogs.officezealot.com/legault/archive/2009/08/13/21577.aspx
    • http://www.officekb.com/Uwe/Forum.aspx/outlook-prog-addins/3142/Apply-Categories-to-other-users-Outlook-2007
    • http ://help.wugnet.com/office/set-master-category-list-Outlook-2007-ftopict1095935.html
    • http ://forums.slipstick.com/showthread.php?t=18189
    • http ://msdn.microsoft.com/en-us/library/ee203806%28EXCHG.80%29.aspx

    The hack itself is show below:

    using System;
    using System.Text;
    using System.Xml;
    using System.IO;
    using Microsoft.Office.Interop.Outlook;
    
    namespace OutlookHack
    {
        public static class OutlookCategoryHelper
        {
            private const string CategoryListStorageItemIdentifier = "IPM.Configuration.CategoryList";
            private const string CategoryListPropertySchemaName = @"http://schemas.microsoft.com/mapi/proptag/0x7C080102";
            private const string CategoriesXmlElementNamespace = "CategoryList.xsd";
            private const string XmlNamespaceAttribute = "xmlns";
            private const string CategoryElement = "category";
            private const string NameAttribute = "name";
    
            public static void RenameCategory(string oldName, string newName, Application outlookApplication)
            {
                MAPIFolder calendarFolder = outlookApplication.Session.GetDefaultFolder(
                    OlDefaultFolders.olFolderCalendar);
                StorageItem categoryListStorageItem = calendarFolder.GetStorage(
                    CategoryListStorageItemIdentifier, OlStorageIdentifierType.olIdentifyByMessageClass);
    
                if (categoryListStorageItem != null)
                {
                    PropertyAccessor categoryListPropertyAccessor = categoryListStorageItem.PropertyAccessor;
                    string schemaName = CategoryListPropertySchemaName;
                    try
                    {
                        // next statement raises Out of Memory error if property is too big
                        var xmlBytes = (byte[])categoryListPropertyAccessor.GetProperty(schemaName);
    
                        // the byte array has to be translated into a string and then the XML has to be parsed
                        var xmlReader = XmlReader.Create(new StringReader(Encoding.UTF8.GetString(xmlBytes)));
    
                        // xmlWriter will write new category list xml with renamed category
                        XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = ("\t") };
                        var stringWriter = new StringWriter();
                        var xmlWriter = XmlWriter.Create(stringWriter, settings);
    
                        xmlReader.Read(); // read xml declaration
                        xmlWriter.WriteNode(xmlReader, true);
                        xmlReader.Read(); // read categories
                        xmlWriter.WriteStartElement(xmlReader.Name, CategoriesXmlElementNamespace);
                        while (xmlReader.MoveToNextAttribute())
                        {
                            if (xmlReader.Name != XmlNamespaceAttribute) // skip namespace attr
                            {
                                xmlWriter.WriteAttributeString(xmlReader.Name, xmlReader.Value);
                            }
                        }
                        while (xmlReader.Read())
                        {
                            switch (xmlReader.NodeType)
                            {
                                case XmlNodeType.Element: // read category
                                    xmlWriter.WriteStartElement(CategoryElement);
                                    while (xmlReader.MoveToNextAttribute())
                                    {
                                        if ((xmlReader.Name == NameAttribute) && (xmlReader.Value == oldName))
                                        {
                                            xmlWriter.WriteAttributeString(NameAttribute, newName);
                                        }
                                        else
                                        {
                                            xmlWriter.WriteAttributeString(xmlReader.Name, xmlReader.Value);
                                        }
                                    }
                                    xmlWriter.WriteEndElement();
                                    break;
                                case XmlNodeType.EndElement: // categories ended
                                    xmlWriter.WriteEndElement();
                                    break;
                            }
                        }
                        xmlReader.Close();
                        xmlWriter.Close();
    
                        xmlBytes = Encoding.UTF8.GetBytes(stringWriter.ToString());
                        categoryListPropertyAccessor.SetProperty(schemaName, xmlBytes);
                        categoryListStorageItem.Save();
                    }
                    catch (OutOfMemoryException)
                    {
                        // if error is "out of memory error" then the XML blob was too big
                    }
                }
            }
        }
    }
    

    This helper method must be called prior to category renaming, e.g.:

     var session = Application.Session;
     var categories = session.Categories;
     var category1 = session.Categories[1];
    
     //catefory1.Name is "Group1" before executing line below
     OutlookCategoryHelper.RenameCategory(category1.Name, "TEST!!!", Application);
     category1.Name = "TEST!!!";
    
     Marshal.ReleaseComObject(category1);
     Marshal.ReleaseComObject(categories);
     Marshal.ReleaseComObject(session);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing outlook 2007 add in, and facing problems with Outlook Security MessageBoxes
I am currently engaged in developing a add-in for MS outlook 2007. I need
I am developing an addin to Microsoft Outlook. The following code works fine if
I'm developing my first Word 2007 addin, and I've added an OfficeRibbon to my
I am developing an add-in for Outlook. One requirement is to add a toolbar
I've been developing a C# (WinForms) application that uses the Office 2007 PIAs to
Developing websites are time-consuming. To improve productivity, I would code a prototype to show
Developing a .NET WinForms application: how can I check if the window is in
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.
Developing server side code i finally got my eyes X-crossed trying to write -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.