Categories Not Saved

S

spottedmahn

I'm updating my categories in code using the Com objects and I see the
changes in Outlook but when I close and re-open the changes are not there.

More detailed description:
-Outlook 2007 running
-Start my app
-Run code to update the category colors and shortkeys
-I see the color changes in Outlook
-Close my app
-Close Outlook
-Reopen Outlook, changes are gone.
 
K

Ken Slovak - [MVP - Outlook]

It's hard to tell what you're doing without seeing any code, but are you
saving whatever changes you're making?
 
S

spottedmahn

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; }
}
}
 
K

Ken Slovak - [MVP - Outlook]

The line that I see on a brief scan of the code that actually adds a new
category to the Categories collection is this:

this.olNS.Categories.Add(Cat.Name, Cat.Color, Cat.ShortcutKey);

Are you sure this line is actually being executed in your code? Maybe add a
Debug.Writeline() call just before that line to verify it is being hit,
otherwise whatever you do won't persist.
 
K

Ken Slovak - [MVP - Outlook]

When I get a chance I'll load your code and see what results I get.
 
M

Manfred

Hi all,

we have a similar problem. We are using two vb-scripts, the first one to
delete all existing categories and a second one to "install" our predefined
categories. The two scripts were working since Jan/Feb 2009 with Outlook 2007
SP1. It seems that the scripts for the categories are not working anymore
since installing Office 2007 SP2.

We have the same symptoms:
- Outlook 2007 running
- Run one of our vb-script (delete categories or install categories)
- I see all categories deleted and then all our custom predefined categories
- Close Outlook
- Reopen Outlook
- All changes in categories are gone.

Any idea or solution?

Manfred
 
K

Ken Slovak - [MVP - Outlook]

As I said to the other poster, I can't repro this problem here on a couple
of Outlook 2007 SP2 systems. I plan to test the poster's code when I get a
chance to see what's going on. All I can say is that I have my own addin
code that completely changes the categories list and it continues to work on
SP2.

If I do turn up a but created by SP2 I'll report it to MS, but that won't
help until or if MS fixes the problem.
 
M

Michael Bauer [MVP - Outlook]

Is your default mail account by chance IMAP? That could explain it as IMAP
doesn't support categories. Outlook won't try to write the categories to the
Master Category List until you close it, and that's when they get lost.

Other ideas: you're connected to a mailserver other than Exchange, or you
don't have the permission to write to the default calendar of the mailbox.

Did you test already whether or not you can add categories to the mailbox by
using Outlook's Categorize dialog?

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Wed, 24 Jun 2009 10:15:01 -0700 schrieb spottedmahn:
 
K

Ken Slovak - [MVP - Outlook]

Good thinking, Michael, I hadn't thought of IMAP or any HTTP based stores
where the PST is just a mirror into that server. None of those would support
persisting categories. Nor would a BCM store unless the BCM database
supported synching up categories.
 
K

Ken Slovak - [MVP - Outlook]

I tested the code and a quickie VBA macro, as well as one of my own addins
that uses VB6, and I cannot reproduce any problem in persisting changes to
the categories list. See the post by Michael Bauer and see if what he says
applies to your situation.
 
S

spottedmahn

I hope I'm not double posting... I clicked post but the dialog never went away.

No, I don't we are using IMAP but how do I verify? If I look at my account
settings the type is "Exchange" which suspect means MAPI.

I am connecting to an Exchange server.

Are you asking if I can update my calendar? If so, then yes I can modify my
calendar.

Yes, I can add categories using Outlook dialog. To test I added a new
category, assigned it to an email, remoted into our terminal server, opened
Outlook and the email was there with the new category.


Thanks,
Mike D.
 
S

spottedmahn

Hi Ken, thanks for testing the code.

I have read Michael Bauer's post and posted a reply.


Mike D.
 
M

Michael Bauer [MVP - Outlook]

If you use the Outlook dialog to add a category, see if it still exists in
your Master Category List, i.e. the list you see when you click the
Categorize button, after re-starting Outlook.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Mon, 29 Jun 2009 09:52:01 -0700 schrieb spottedmahn:
 
S

spottedmahn

Yes, I have added a new category via the Outlook dialog, close and reopened
Outlook and the category is there.
 
M

Manfred

Hello Ken,

here is my sample code for deleting existing categories:

Option Explicit

Dim oOutlook : Set oOutlook = CreateObject("Outlook.Application")
Dim oNameSpace : Set oNameSpace = oOutlook.GetNameSpace("MAPI")
Dim theCategories
Dim theCategory
Dim i


Set theCategories = oNameSpace.Categories

For Each theCategory in theCategories
WScript.StdOut.Writeline theCategory.Name & theCategory.CategoryID
Next

For i = 1 to theCategories.Count
theCategories.Remove 1
Next


I have tested this code once again on a machine with office 2007 sp1 and the
categories were deleted correctly.

After installation of sp2 it seems, that the changes (deleting) of
categories are not saved to the exchange store. The code is running and the
categories seem to be deleted, but after closing and starting outlook, all my
categories are back again.

Any idea or solution?

Manfred
 
K

Ken Slovak - [MVP - Outlook]

It's obviously related to your other problem, but I can't repro it here on
any of my Outlook 2007 SP2 systems. So it's specific to your computer.

A word of advice, when deleting items from a collection use a count down For
loop, not a count up loop. Otherwise the loop usually ends up deleting or
moving only 1/2 of the items in each pass.
 
M

Manfred

Hi Ken,

no, this is not a problem with one computer, we have this problem on all
computers.
And it is definitivly reproducable working with SP1 and NOT working with SP2.

The loop was working correctly all the time from Jan 2009 to Jun 2009
(installing SP2), so this is not the problem.

In my opinion this is a problem with saving the changes back to the exchange
mailbox store.

Manfred
 
K

Ken Slovak - [MVP - Outlook]

It's obviously not a universal problem since I can't repro it here.

All I can suggest is to open a support case with MS and see what they say.
If it's their bug they will refund or waive the charges for the support
case, if it's not a bug then you pay for the case.
 
S

spottedmahn

Thanks for all of your input Ken.

I'll open a case with MSFT and post the results.

Regards,
Mike D.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top