title: Programmatically add multiple categories to Outlook 2010
body: <p>I am trying to create multiple categories in Outlook 2010 using C#. I am able to successfully generate an executable that will create one category but when I add code to create a second category it will still only add the first one and not the second. If The first category exists it will then add the second one but it will not create both from scratch at the same time.</p>
  
  <p>Below is my code. Any help is greatly appreciated.</p>
  
  <pre><code>using System;
  using System.Linq;
  using Outlook = Microsoft.Office.Interop.Outlook;
  using Microsoft.Office.Interop.Outlook;
  
  
  namespace OutlookCategory
  {
      class Program
      {
          static void Main(string[] args)
          {
              AddACategory();
          }
  
          private static void AddACategory()
          {
              var app = new Application();
              Outlook.Categories categories = app.Session.Categories;
              if (!CategoryExists("TEST 1", app))
              {
                  categories.Add("TEST 1", Outlook.OlCategoryColor.olCategoryColorDarkBlue);
              }
              if (!CategoryExists("TEST 2", app))
              {
                  categories.Add("TEST 2", Outlook.OlCategoryColor.olCategoryColorDarkBlue);
              }
  
          }
  
          private static bool CategoryExists(string categoryName, Application app)
          {
              try
              {
                  Outlook.Category category =
                      app.Session.Categories[categoryName];
                  if (category != null)
                  {
                      return true;
                  }
                  else
                  {
                      return false;
                  }
              }
              catch { return false; }
          }
      }
  }
  </code></pre>