Hi Ken, thanks for the response.
How do I save the changes?
Here is most of the code... please let me know if this is not enough.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookCategoryHelper
{
public class OutlookCategoriesHelper
{
string OutlookNameSpace = "MAPI";
Outlook._Application olApp;
Outlook._NameSpace olNS;
public OutlookCategoriesHelper(Outlook.ApplicationClass AppIn)
{
this.olApp = AppIn;
this.olNS = olApp.GetNamespace(this.OutlookNameSpace);
}
//todo maybe need to create excel program with drop downs,
//copy paste to a tab delimited, lookup enums by name
string CatInvestAndBankingName = "Investments and Banking";
Outlook.OlCategoryColor CatInvestAndBankingColor =
Outlook.OlCategoryColor.olCategoryColorOlive;
Outlook.OlCategoryShortcutKey CatInvestAndBankingKey =
Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone;
string CatSifCloseParnersName = "SIF - Close Partners";
Outlook.OlCategoryColor CatSifCloseParnersColor =
Outlook.OlCategoryColor.olCategoryColorSteel;
Outlook.OlCategoryShortcutKey CatSifCloseParnersKey =
Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone;
string CatSifFrsaUsisName = "SIF - FRSA USIS";
Outlook.OlCategoryColor CatSifFrsaUsisColor =
Outlook.OlCategoryColor.olCategoryColorBlue;
Outlook.OlCategoryShortcutKey CatSifFrsaUsisKey =
Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone;
string CatSifMembersName = "SIF - Members";
Outlook.OlCategoryColor CatSifMemberColor =
Outlook.OlCategoryColor.olCategoryColorRed;
Outlook.OlCategoryShortcutKey CatSifMemberKey =
Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF2;
string CatSifVendorsName = "SIF - Vendor";
Outlook.OlCategoryColor CatSifVendorsColor =
Outlook.OlCategoryColor.olCategoryColorOrange;
Outlook.OlCategoryShortcutKey CatSifVendorsKey =
Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone;
string CatTech3rdPartyName = "Tech - 3rd Party Rpting";
Outlook.OlCategoryColor CatTech3rdPartyColor =
Outlook.OlCategoryColor.olCategoryColorMaroon;
Outlook.OlCategoryShortcutKey CatTech3rdPartyKey =
Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone;
string CatTechDevName = "Tech - Dev";
Outlook.OlCategoryColor CatTechDevColor =
Outlook.OlCategoryColor.olCategoryColorGreen;
Outlook.OlCategoryShortcutKey CatTechDevKey =
Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone;
string CatTechSuportName = "Tech - Support";
Outlook.OlCategoryColor CatTechSupportColor =
Outlook.OlCategoryColor.olCategoryColorYellow;
Outlook.OlCategoryShortcutKey CatTechSupportKey =
Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone;
public List<OutlookCategory> SifCategories
{
get
{
List<OutlookCategory> Results = new List<OutlookCategory>();
string Name;
Outlook.OlCategoryColor Color;
Outlook.OlCategoryShortcutKey Key;
OutlookCategory Cat;
//Investment and Banking
Name = this.CatInvestAndBankingName;
Color = this.CatInvestAndBankingColor;
Key = this.CatInvestAndBankingKey;
Cat = CreateNewOutlookCategory(Name, Color, Key);
Results.Add(Cat);
//SIF - Close Partners
Name = this.CatSifCloseParnersName;
Color = this.CatSifCloseParnersColor;
Key = this.CatSifCloseParnersKey;
Cat = CreateNewOutlookCategory(Name, Color, Key);
Results.Add(Cat);
//SIF - Members
Name = this.CatSifMembersName;
Color = this.CatSifMemberColor;
Key = this.CatSifMemberKey;
Cat = CreateNewOutlookCategory(Name, Color, Key);
Results.Add(Cat);
//SIF - FRSA USIS
Name = this.CatSifFrsaUsisName;
Color = this.CatSifFrsaUsisColor;
Key = this.CatSifFrsaUsisKey;
Cat = CreateNewOutlookCategory(Name, Color, Key);
Results.Add(Cat);
//SIF - Vendors
Name = this.CatSifVendorsName;
Color = this.CatSifVendorsColor;
Key = this.CatSifVendorsKey;
Cat = CreateNewOutlookCategory(Name, Color, Key);
Results.Add(Cat);
//Tech - 3rd Party Reporting
Name = this.CatTech3rdPartyName;
Color = this.CatTech3rdPartyColor;
Key = this.CatTech3rdPartyKey;
Cat = CreateNewOutlookCategory(Name, Color, Key);
Results.Add(Cat);
//Tech - Support
Name = this.CatTechSuportName;
Color = this.CatTechSupportColor;
Key = this.CatTechSupportKey;
Cat = CreateNewOutlookCategory(Name, Color, Key);
Results.Add(Cat);
//Tech - Dev
Name = this.CatTechDevName;
Color = this.CatTechDevColor;
Key = this.CatTechDevKey;
Cat = CreateNewOutlookCategory(Name, Color, Key);
Results.Add(Cat);
//blank
//
//Color = this.Cat;
//Key = this.Cat;
//Name = this.Cat;
//Cat = CreateNewOutlookCategory(Name, Color, Key);
//Results.Add(Cat);
return Results;
}
}
private OutlookCategory CreateNewOutlookCategory(string NameIn,
Outlook.OlCategoryColor olCategoryColorIn, Outlook.OlCategoryShortcutKey
olCategoryShortcutKeyIn)
{
OutlookCategory Result = new OutlookCategory();
Result.Color = olCategoryColorIn;
Result.ShortcutKey = olCategoryShortcutKeyIn;
Result.Name = NameIn;
return Result;
}
public IEnumerable<Outlook.Category> CategoriesList
{
get
{
Outlook.Categories Cats = this.olNS.Categories;
//foreach (Outlook.Category item in Cats)
//{
//}
IEnumerable<Outlook.Category> Results =
Cats.Cast<Outlook.Category>();
//List<Outlook.Category> ResultsT = Results.ToList();
return Results;
}
}
public void CreateOrUpdateSifCategories()
{
foreach (OutlookCategory Cat in this.SifCategories)
{
CreateOrUpdateSifCategory(Cat);
}
}
private void CreateOrUpdateSifCategory(OutlookCategory Cat)
{
var Query = this.CategoriesList.Where(x =>
x.Name.Equals(Cat.Name));
if (Query.Any())
{
Outlook._Category OCat = Query.Take(1).Single();
OCat.Color = Cat.Color;
OCat.ShortcutKey = Cat.ShortcutKey;
}
else
{
this.olNS.Categories.Add(Cat.Name, Cat.Color,
Cat.ShortcutKey);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookCategoryHelper
{
public class OutlookCategory
{
public string Name { get; set; }
public Outlook.OlCategoryColor Color { get; set; }
public Outlook.OlCategoryShortcutKey ShortcutKey { get; set; }
}
}