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:
The sample code is here:
I hope someone finds it useful!
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.