Solved

Programmatically creating search folders in Outlook 2007

Posted on 2010-09-13
3
1,335 Views
Last Modified: 2012-05-10
I'm trying to programatically create a search folder in outlook 2007. I've figured out how to do it, but I can't figure out the exact filter for what I want...

I'm trying to change "sFilter" to filter on "message class" = "IPM.Note.Voice.Unity" and can't figure out what the URN would be for message class. I've tried searching, and randomly putting filter strings together to no avail. Can't find any documentation on this.

I've tried all of these filter queries:

            //string sFilter = "\"urn:schemas:mailheader:subject\" LIKE 'RE:%'";
            //string sFilter = "\"urn:schemas:messageclass\" LIKE '%IPM.Note.Voice.Unity'";
            //string sFilter = "\"urn:schemas:mailheader:message-id\" LIKE '%IPM.Note.Voice.Unity'";
            //string sFilter = "\"DAV:contentclass\" LIKE '%IPM.Note.Voice.Unity'";
            //string sFilter = "\"http://schemas.microsoft.com/exchange/outlookmessageclass\" = 'IPM.Note.Voice.Unity'";
            //string sFilter = "\"urn:content-classes:message\" LIKE 'IPM.Note.Voice.Unity'";
            //string sFilter = "\"urn:schemas:mailheader:content-class\" LIKE 'IPM.Note.Voice.Unity'";
            //string sFilter = "\"urn:content-classes\" LIKE 'IPM.Note.Voice.Unity'";
            //string sFilter = "\"urn:content-class\" LIKE 'IPM.Note.Voice.Unity'";
            //string sFilter = "\"urn:contentclass\" LIKE 'IPM.Note.Voice.Unity'";

            //string sFilter = "\"urn:schemas:messageclass\" LIKE '%Unity%'";
            //string sFilter = "\"urn:schemas:mailheader:message-id\" LIKE '%Unity%'";
            //string sFilter = "\"urn:content-classes:message\" LIKE '%Unity%'";
            //string sFilter = "\"urn:schemas:mailheader:content-class\" LIKE '%Unity%'";
            //string sFilter = "\"urn:content-classes\" LIKE '%Unity%'";
            //string sFilter = "\"urn:content-class\" LIKE '%Unity%'";
            //string sFilter = "\"urn:contentclass\" LIKE '%Unity%'";


Ideas?
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MAPIFolder oInbox = oApp.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox);
string sFolderPath = oInbox.FolderPath;
string sScope = "SCOPE ('deep traversal of \"" + sFolderPath + "\"')";
string sFilter = "\"urn:schemas:mailheader:subject\" LIKE 'RE:%'";
Microsoft.Office.Interop.Outlook.Search oSearch =  oApp.AdvancedSearch(sScope, sFilter, false, "RE folders");
Microsoft.Office.Interop.Outlook.MAPIFolder oSearchFolder = oSearch.Save("RE folders");

Open in new window

0
Comment
Question by:sypkenjm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33669444
string sFilter = "\"urn:schemas:mailheader:content-class\" LIKE 'IPM.Note.Voice.Unity'";

this should have worked.. What is happening when you give this filter ??
0
 

Author Comment

by:sypkenjm
ID: 33671639
I just tried that one again with the same results. Basically, what happens with all of the sFilter strings I've tried so far, is that it creates the search filter in Outlook; when I click on it, Outlook tells me "There are no items to show in this view", and when I right click on it and hit "Customize this Search Folder", the "Criteria" button is greyed out.

When I create the search folder manually, there are items in the view, and I can hit the customize button.
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 33699663
can yout try this add see if any exception is throwin in the catch
class Program
    {
        static void Main(string[] args)
        {
            Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.MAPIFolder oInbox = oApp.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            string sFolderPath = oInbox.FolderPath;
            string sScope = "SCOPE ('deep traversal of \"" + sFolderPath + "\"')";
            string sFilter = "\"urn:schemas:mailheader:content-class\" LIKE 'IPM.Note'";
            // string sFilter = "\"urn:schemas:mailheader:subject\" LIKE 'RE:%'";
            oApp.AdvancedSearchComplete += new ApplicationEvents_11_AdvancedSearchCompleteEventHandler(oApp_AdvancedSearchComplete);
            Microsoft.Office.Interop.Outlook.Search oSearch = oApp.AdvancedSearch(sScope, sFilter, false, "RE folders");
            // Microsoft.Office.Interop.Outlook.MAPIFolder oSearchFolder = oSearch.Save("RE folders");
            Console.Read();
        }

        static void oApp_AdvancedSearchComplete(Search SearchObject)
        {
            try
            {
                var item1 = SearchObject.GetTable();
                item1.GetArray(SearchObject.Results.Count);

                foreach (Microsoft.Office.Interop.Outlook.MailItem item in SearchObject.Results)
                {
                    
                }
            }
            catch
            {
            }
        }


    }

Open in new window

0

Featured Post

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question