Does VSTO, or the Outlook object model, offer the ability to list out all the categories shown in the Categories dialog or Master Category dialog. I would like to be able to allow my user to pick a category from that list without having to show the categories dialog with olApptItem.ShowCategoriesDialog.

Enumerating Outlook Categories
C Dickson
Hello Siggi,
Yes, wrong forum but can't resist anyway - sorry
To get the list of 'Master Categories' there is no API. The only way is via a registry key. For different versions of Outlook this is encoded differently. Here's an example (rough) bit of code to get you going:
// Returns a comma delimited list of categories, pass in "11" as the etc as the major Outlook version
public
string ReadCategoriesRegKey(string olVer){
logi("ReadCategoriesRegKey entered");
// If Outlook 2000 (9.0), then it's a comma delimited string in
// HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Outlook\Categories\MasterList
// If Outlook 2002/XP (10.0) then it's a binary key, command delimited (I guess for unicode)
// HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\Categories\MasterList
// Same in 2003 (11.0) , just diiferent ver number
// HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Categories\MasterList
// In 2007 Beta (12.0) it looks like they go in the PST file via API...
try{
string fullKey = @"Software\Microsoft\Office\" + olVer + @".0\Outlook\Categories\";
RegistryKey baseKey = Registry.CurrentUser;
RegistryKey subKey = baseKey.OpenSubKey(fullKey);
// if we don't have a key this means that the Outlook user has never used Master Categories
// before so we need to create the key
if (subKey == null)
{
baseKey.CreateSubKey(fullKey);
// Open our subkey
subKey = baseKey.OpenSubKey(fullKey, true);
subKey.SetValue("MasterList", null);
}
string keyValue = "Unknown";
// Sometimes the key isn't there...
object byteValue = null;
byteValue = subKey.GetValue("MasterList");
subKey.Close() ;
baseKey.Close();
if (byteValue == null)
return("");
// Convert from Unicode into a normal string if version more than 9.0
if ((olVer == "11") || (olVer=="10"))
{
// Create two different encodings.
Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;
// Convert the string into a byte[].
byte[] unicodeBytes = (byte[])byteValue;
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
// Convert the new byte[] into a char[] and then into a string.
char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
keyValue = new string(asciiChars);
return(keyValue);
}
else
if (olVer == "9")
{
// Outlook 9 (2000) didnt encode the regkey as unicode, so should be good to pass back unfiddled, maybe...
return(keyValue);
}
}
catch (System.Exception ex)
{
loge("Caught!", ex);
}
// Don't know, so no categories
return("");
}
throsturi
Hello,
I did a quick search, couldn't find ways to use OOM to get all the categories shown in the appointment item Categories dialog. Is there any particular reason you can't display the CategoriesDialog
This forum is mainly for Outlook issues that directly pertain to the Visual Studio Tools for Office tools, so you will be better served by posing this question to a forum or newsgroup wholly dedicated to issues such as this one. Here are some resources you should consult for best results:
microsoft.public.office.developer.vba
microsoft.public.office.developer.outlook.vba
microsoft.public.office.developer.outlook.forms
http://msdn.microsoft.com/office/understanding/outlook
http://www.outlookcode.com
http://www.officezealot.com
Best of luck with VSTO and Outlook!
Mei Liang
-----------------------------------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
ueqt
The main reason is simply UI design, I would like to be able to have everything in one window.
I'm sorry I thought was directly related to using VSTO with outlook. I'll post this question to microsoft.public.office.developer.outlook.vba and see if they have an answer.
Thanks for your help.