Hi all,
I am using .net framework 3.5 by using C# to configure outlook 2007
I need to import all categories from outlook 2007 to my application particularly on dropdownlist, i want to listed all the categories
from outlook to one combobox in my application, i don't know how to get all the categories,

if anyone know reply

Recommended Answers

All 2 Replies

This snippet demonstrates how to obtain several objects from an Outlook folder. I don't use Outlook, so I can't really verify it, but maybe it will help get you started: Outlook Folder Objects

This snippet demonstrates how to obtain several objects from an Outlook folder. I don't use Outlook, so I can't really verify it, but maybe it will help get you started: Outlook Folder Objects

I went ahead and created a method for this code I referred, and there was a syntax error, which is fixed in the snippet I am including here. I began testing, but got as far as the Logon call when it started up the Outlook Install Wizard. So, I stopped because I didn't want to install Outlook. I am passing in a sub folder parameter in the definition, but have commented out the line and gone with the hardcoded folder from the Folders collection because I didn't know a valid sub folder to provide. Anyway, here is the code if you want to try it:

public static void GetOutlookItems(string subFolderName)
        {
            Microsoft.Office.Interop.Outlook.Application app = null;
            Microsoft.Office.Interop.Outlook._NameSpace ns = null;
            Microsoft.Office.Interop.Outlook.PostItem item = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;

            try
            {
                app = new Microsoft.Office.Interop.Outlook.Application();
                ns = app.GetNamespace("MAPI");

                // The following line will begin the install wizard for Outlook if not installed.
                ns.Logon(null, null, false, false);

                inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
                //subFolder = inboxFolder.Folders[subFolderName]; 
                subFolder = inboxFolder.Folders[1];// also works-- which folder?
                Console.WriteLine("Folder Name: {0}, EntryId: {1}", subFolder.Name, subFolder.EntryID);
                Console.WriteLine("Num Items: {0}", subFolder.Items.Count.ToString());

                for (int i = 1; i <= subFolder.Items.Count; i++)
                {
                    item = (Microsoft.Office.Interop.Outlook.PostItem)subFolder.Items[i];
                    Console.WriteLine("Item: {0}", i.ToString());
                    Console.WriteLine("Subject: {0}", item.Subject);
                    Console.WriteLine("Sent: {0} {1}", item.SentOn.ToLongDateString(), item.SentOn.ToLongTimeString());
                    Console.WriteLine("Categories: {0}", item.Categories);
                    Console.WriteLine("Body: {0}", item.Body);
                    Console.WriteLine("HTMLBody: {0}", item.HTMLBody);
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                ns = null;
                app = null;
                inboxFolder = null;
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.