Performing Outlook Advanced Search from your C# Application

by Digvijay 18. September 2009 02:10

Over this weekend, I was just trying to perform a search in my (exchange account) Outlook inbox  via a C# WinForms application and initially i assumed i would need to write an add-in and do so. However a quick search revealed that i could just use the interop assemblies and perform the search:

ApplicationClass app = new ApplicationClass();
app.AdvancedSearchComplete += 
        new ApplicationEvents_11_AdvancedSearchCompleteEventHandler(app_AdvancedSearchComplete);
 
string folder = "'" + app.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox).FolderPath + "'";
 
app.AdvancedSearch(folder, "urn:schemas:httpmail:subject LIKE '%" + searchText + 
        "%' OR urn:schemas:httpmail:textdescription LIKE '%" + 
        searchText + "%'", true, DateTime.Now.Millisecond);
 

 

This above snippet sets up all we need to do the search and we handle it as follows:

void app_AdvancedSearchComplete(Search SearchObject)
{
    if (!DesignMode)
    {
        try
        {
            if (SearchObject.Results.Count > 0)
            {
                items.Clear();
                MailItem mailItemLoop = SearchObject.Results.GetFirst() as MailItem;
                do
                {
                    if (mailItemLoop != null)
                    {
                        items.Add(new OutlookSearchItem(mailItemLoop));
                    }
 
                    mailItemLoop = SearchObject.Results.GetNext() as MailItem;
                }
                while (mailItemLoop != null);
            }
        }
        catch(System.Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        finally
        {
            // Do data binding for display                 
        }
    }

Here is a screenshot of the sample application:

AOS

The sample code is here:

I hope someone finds it useful!

Tags:

.NET | VSTO

Adding Custom Prerequisites to your MSI package

by Digvijay 16. May 2008 18:05

Recently I made an installer for an Outlook 2007 Add-in developed using VSTO/VS 2008 and it worked fine on all development machines I have, but I noticed that it would fail to run on a fresh VPC image.

I had added all the necessary CA permissions, correct registry entries to the installer but I could not figure out what was missing!

 

A bit of goggling and I found some interesting things that I would share here:

 

A shared office 2007 add-in would need the following as prerequisites

  • .NET Framework
  • VSTO Runtime
  • Office 2007 Primary Interop Assemblies

So I decided to go ahead and add them to my installer but to my surprise the VS 2008 prerequisite dialog did not contain any of these. So how do i add them to the prerequisites dialog on my development machine???

It seems gotdotnet hosted such a tool which is now moved to codeplex. I could add all these 3 as a prerequisite and boom! it worked. This tool called the BMG or the Bootstrap Manifest Generator can take up arbitrary executables and MSI packages and add them as custom prerequisites!

 

A click once version of BMG can be found here.

 

Here is a nice article describing it.

Tags:

Installers | Office Development | VSTO

 

About Digvijay

  Digvijay Chauhan
I am a developer living in Stockholm, Sweden and I love to program and work on cutting edge technologies in the Microsoft Technology space.

LinkedIn Twitter StackOverflow

Certifications

Digvijay Chauhan Microsoft Certification Logo

Other Pages

RecentPosts

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

Most comments

Live Traffic

Live Traffic Feed
  Västra Frölunda, Vastra Gotaland arrived from digvijay.eu on "blank_page"

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Translate