Pieter van der Westhuizen

MS Outlook Advanced Regions, Folder Views and Add-in Express 2010

In this week’s post, we’ll build an add-in for Northwind Traders with which they will be able to set a different view on their Inbox in order to see a time-based view on when orders have been received. We’ll be using an advance forms region to give our users an easy-to-use interface.

Start by creating a new ADX COM Add-in Project in Visual Studio 2010.

Creating a new ADX COM Add-in Project in Visual Studio 2010

Select Visual C# for our programming language and Microsoft Office 2010 as the Minimum supported Office version. For this example, only select Microsoft Office in the Supported Applications list. Finish the wizard and add a new ADX Outlook Form to the project.

Adding a new Add-in Express Outlook Form

This form will display a list of Northwind’s customers and the filter range for our Inbox.

Outlook Form to display a list of Northwind's customers

Next, switch to the AddinModules’ designer and add a new ADXOutlookFormsManager.

Adding a new ADXOutlookFormsManager

Select the ADXOutlookFormsManager and click the ellipses (…) button next to its Items property. Add a new item to the forms collection by clicking the Add button. Change the ExplorerItemTypes property to Mail and the ExplorerLayout property to BottomNavigationPane. Select the ADXOutlook Form you’ve added earlier from the list of items in the FormClassName property. Click the OK button to close the Forms Collection Editor window.

To save time, we’ll create the view for the folder in Outlook and filter the view in our add-in. To create the view, select Manage Views from the Change Views menu in Outlook:

Creating the view for the Outlook folder

Create a new View, and set the type of view to Day/Week/Month. Name the view InboxCalendarView.

Add the following code to the ADX Outlook form’s Set Filter button:

private void btnSetFilter_Click(object sender, EventArgs e)
{
Outlook._Explorer myExpl = (Outlook._Explorer)this.ExplorerObj;
Outlook.MAPIFolder currFolder = (Outlook.MAPIFolder)myExpl.CurrentFolder;
String viewXml = currFolder.CurrentView.XML;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(viewXml);
XmlNode rootNode = xmlDoc.DocumentElement;
XmlNode filterNode = rootNode.SelectSingleNode("filter");
 
if (filterNode != null)
{
    filterNode.InnerText = "urn:schemas:httpmail:sender LIKE '%" + cboCustomers.Text + "%'";
    filterNode.InnerText += "AND %" + cboReceived.Text.ToLower() + "(urn:schemas:httpmail:datereceived)%";
}
else
{
    XmlElement filterElement = xmlDoc.CreateElement("filter");
    filterElement.InnerText = "urn:schemas:httpmail:sender LIKE '%" + cboCustomers.Text + "%'";
    filterNode.InnerText += "AND %" + cboReceived.Text.ToLower() + "(urn:schemas:httpmail:datereceived)%";
    rootNode.AppendChild(filterElement);
}
 
currFolder.CurrentView.XML = xmlDoc.InnerXml;
currFolder.CurrentView.Apply();
Marshal.ReleaseComObject(myExpl);
Marshal.ReleaseComObject(currFolder);
}

To see a list of all fields available  when specifying the urn:schemas:httpmail, see:

urn:schemas:httpmail: Namespace on MSDN

After building and running the solution, start MS Outlook. You will see an advanced Outlook region below the navigation bar.

Advanced Outlook region below the navigation bar

The Customer combo box will show a list of Northwind’s customers. When the user clicks the Set Filter button, the current selected folder will only display mail items from the selected customer received within the selected timeframe. If you selected the InboxCalendarView we’ve created earlier, your folder view will look like this:

Custom Outlook calendar view

Now, the Northwind sales representatives can easily see when they received emails from specific customers.

Thank you for reading. Until next time, keep coding!

You may also be interested in:

Advanced Outlook view and form regions – Basic concepts
Advanced Outlook view and form region types

2 Comments

  • Sourabh nagar says:

    I don’t see adx com addin for visual studio 2010 under extensibility.. How do I activate it?

  • Eugene Astafiev says:

    Hi Sourabh,

    Please make sure that you have Add-in Express for Office and .net installed on your PC.

Post a comment

Have any questions? Ask us right now!