Pieter van der Westhuizen

Outlook 2010 Solutions Module revisited

It’s been a year and seven months since my first article about the Outlook 2010 Solutions Module. Time sure flies when you’re having fun. Since I first wrote the article, I received numerous comments and questions about the Outlook 2010 Solutions module, mostly on how to programmatically add items to it.

I thought that I would do a post to show you some more advanced techniques when it comes to using the Solutions module component programmatically. In this article we’ll cover the following:

  • Adding a root solutions folder in code;
  • Adding children to the root solutions folder;
  • Adding ADX forms to the Outlook Forms manager programmatically; and
  • Changing the FormClassName property (i.e. re-use the same form for all regions) programmatically and refreshing the form region.

Let’s get started by creating a new COM Add-in project in Visual Studio 2010.

Creating a new COM Add-in project in Visual Studio 2010

Select your language of choice and Microsoft Office 2010 as the minimum supported Office version.

Select your programming language and Microsoft Office 2010 as the minimum supported version

Since the Solutions Module is only available in Microsoft Outlook, only select Microsoft Outlook as the supported application.

Select Microsoft Outlook as the supported application

Next, add an ADXOLSolutionModule and ADXOlFormsManager to the AddinModule designer surface.

Adding the ADXOLSolutionModule and ADXOlFormsManager components to the AddinModule designer surface

Click on the AddinModule designer surface to show its properties and add a new event handler for the AddinStartupComplete event by double-clicking next to the event name.

Adding a new event handler for the AddinStartupComplete event

Adding the Solution Module root folder

In the AddinModule_AddinStartupComplete event handler add the following code to create the root folder:

ADXOLSolutionFolder rootFolder = new ADXOLSolutionFolder();
rootFolder.FolderName = "Northwind";
rootFolder.FolderType = ADXOLSolutionFolderType.Notes;

Adding child folders to the root folder

// Child Folder - Sales
ADXOLSolutionFolder salesFolder = new ADXOLSolutionFolder();
salesFolder.FolderName = "Sales";
salesFolder.FolderType = ADXOLSolutionFolderType.Notes;
 
// Sales Folder - Child Folders
ADXOLSolutionFolder customersFolder = new ADXOLSolutionFolder();
customersFolder.FolderName = "Customers";
customersFolder.FolderType = ADXOLSolutionFolderType.Notes;
 
// Contacts Folder - Child Folders
ADXOLSolutionFolder contactsFolder = new ADXOLSolutionFolder();
contactsFolder.FolderName = "Contacts";
contactsFolder.FolderType = ADXOLSolutionFolderType.Contacts;
 
// Orders Folder - Child Folders
ADXOLSolutionFolder ordersFolder = new ADXOLSolutionFolder();
ordersFolder.FolderName = "Orders";
ordersFolder.FolderType = ADXOLSolutionFolderType.Notes;
 
// Add Sub-folders to Sales Folder
salesFolder.Folders.Add(customersFolder);
salesFolder.Folders.Add(contactsFolder);
salesFolder.Folders.Add(ordersFolder);
 
// Add Sales folder to Root Folder
rootFolder.Folders.Add(salesFolder);
 
// Add Root Folder to the Solution Module component
adxolSolutionModule1.Folders.Add(rootFolder);

The code above will create the Solutions module with a root folder including one sub-folder which in turn has three sub-folders.

Solutions module with a root folder including one sub-folder

Next, add a new Outlook Form to your project.

Adding a new Outlook Form to your project

Add an empty label to the form and switch back to the AddinStartupComplete event handler.

Getting the Outlook Default Store folder

Before we can set the folder names for the Forms manager, we need to obtain the Default stores’ name. This is generally your e-mail address or Personal Folders. To get the name use the following code:

// Get the default sore name
Outlook.NameSpace nameSpace = OutlookApp.GetNamespace("MAPI");
Outlook.Store store = nameSpace.DefaultStore;
string defaultStore = store.DisplayName;
Marshal.ReleaseComObject(store);
Marshal.ReleaseComObject(nameSpace);

Programmatically adding forms to the ADX Forms Manager

The following code will add your ADX Outlook Form to the Forms Manager’s item collection. You’ll have to set its FolderName property to the ADXSolutionFolder(Northwind) we’ve created earlier:

// Add item to Forms Manager Collection 
AddinExpress.OL.ADXOlFormsCollectionItem northwindFormItem =
    new AddinExpress.OL.ADXOlFormsCollectionItem(); 
northwindFormItem.FormClassName = "ADXSolutionsModule.MyForm";
northwindFormItem.FolderName = defaultStore + "\\Northwind";
adxOlFormsManager1.Items.Add(northwindFormItem);
northwindFormItem.ExplorerLayout = AddinExpress.OL.ADXOlExplorerLayout.WebViewPane;

Open the ADX Outlook Form and create an event handler for its ADXFolderSwitch event. Add the following code to it:

private void MyForm_ADXFolderSwitch(object sender, ADXFolderSwitchEventArgs args)
{
    Outlook.Folder folder = (Outlook.Folder)this.FolderObj;
    this.label1.Text = folder.FolderPath;
}

This code will display the selected folders’ path on the ADX Outlook form:

The selected folders' path is displayed on the Outlook form

Re-using the same ADX Outlook Form on different folders

You are able to re-use the same ADX Outlook Form on multiple folders. To do this, simply add another ADXOLFormsCollectionItem and set its FormClassName to the same value as the other items.

AddinExpress.OL.ADXOlFormsCollectionItem contactsFormItem =
    new AddinExpress.OL.ADXOlFormsCollectionItem(); 
contactsFormItem.FormClassName = "ADXSolutionsModule.MyForm";
contactsFormItem.FolderName = defaultStore + "\\Northwind\\Sales\\Contacts";
adxOlFormsManager1.Items.Add(contactsFormItem);
contactsFormItem.ExplorerLayout = AddinExpress.OL.ADXOlExplorerLayout.WebViewPane;

The result is that when you switch between the Northwind and Contacts folder the same ADX Outlook form is used, but displays the selected folders’ path.

The same ADX Outlook form is used, but displays the selected folders' path.

Change the FormClassName and refreshing the form

If you need to change ADXOLFormsCollectionItems’ FormClassName property when the user clicks, for example on a ribbon button, add the following code to the button OnClick event:

private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed)
{
    adxOlFormsManager1.Items[0].FormClassName = "ADXSolutionsModule.AnotherForm";
    Outlook._Explorer activeExplorer = OutlookApp.ActiveExplorer();
    adxOlFormsManager1.Items[0].ApplyTo(activeExplorer);
    Marshal.ReleaseComObject(activeExplorer);
}

The ApplyTo method causes the form region to refresh and display the new ADX Outlook form, without the need for the user to switch folders back and forth.

Well, that’s a wrap for the questions you have been asking. Feel free to ask more questions or if there is any other topics you would like me to cover drop me a line on Twitter.

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

Available downloads:

The sample COM Add-in were developed using Add-in Express for Office and .net:

C# sample project
VB.NET sample project

You may also be interested in:

33 Comments

  • Ariel Mears says:

    What if you are using a COM add-in module to contain your forms? How do you specify the name of the formclassname when it’s in a seperate project?

    Thanks for the help!

  • Pieter van der Westhuizen says:

    Hi Ariel,

    Hope I understand your question correct. If you have a separate project that contains the forms, you’ll need to add a reference to that project from your add-in project and then specify the fully qualified class name when setting the form class name.

    For example, let’s assume the project you have your forms in is called MyProject.Forms and the form you’d like to use is called MyForm, you need to specify the name like so:

    contactsFormItem.FormClassName = “MyProject.Forms.MyForm”;

    Hope this helps and thank you for your comment!

  • Ariel Mears says:

    Yes you understand it perfectly. The problem I end up with is this error:
    A TeamViewContentManager.Views.frmWorkspace form instance has not been created.

  • Dmitry Kostochko (Add-in Express Team) says:

    Hi Ariel and Pieter,

    Oh, sorry, my fault. The ADXAddinAdditionalModule component that can be used in an additional class library can contain only UI components such as command bars, ribbon tabs, backstage views and Outlook solution modules. Advanced Outlook forms, advanced task panes and their managers should be located in the main add-in assembly. Sorry again for misleading you and Pieter.

  • Ariel Mears says:

    No problem. Thank you for your answer. Just one last question: If a outlook solution can be in the additional module, do your ADX forms still need to be in the MAIN project, or can they reside in the class project since the outlook solution is in the class project?

  • Dmitry Kostochko (Add-in Express Team) says:

    Ariel,

    Yes, the ADXOlFormsManager component and all your advanced Outlook regions (descendants of the AddinExpress.OL.ADXOlForm class) should be in the main project.

  • Ariel Mears says:

    Great, thanks for the help.

  • Dritan says:

    Hello Pieter,
    I’m following your instructions to create the addin in vs 2012 (vb.net).

    The problem is that when click to Northwind folder myform doesn’t show.
    i dont’t understand where is my problem.
    May you help me please?

    Best regards
    Dritan
    My code is:
    Dim rootFolder As New ADXOLSolutionFolder()
    rootFolder.FolderName = “Northwind”
    rootFolder.FolderType = ADXOLSolutionFolderType.Inbox

    ‘———————————————————————
    ‘ Child Folder – Sales
    Dim salesFolder As New ADXOLSolutionFolder()
    salesFolder.FolderName = “Sales”
    salesFolder.FolderType = ADXOLSolutionFolderType.Inbox

    ‘ Sales Folder – Child Folders
    Dim customersFolder As New ADXOLSolutionFolder()
    customersFolder.FolderName = “Customers”
    customersFolder.FolderType = ADXOLSolutionFolderType.Inbox

    ‘ Contacts Folder – Child Folders
    Dim contactsFolder As New ADXOLSolutionFolder()
    contactsFolder.FolderName = “Contacts”
    contactsFolder.FolderType = ADXOLSolutionFolderType.Inbox

    ‘ Orders Folder – Child Folders
    Dim ordersFolder As New ADXOLSolutionFolder()
    ordersFolder.FolderName = “Orders”
    ordersFolder.FolderType = ADXOLSolutionFolderType.Inbox

    ‘ Add Sub-folders to Sales Folder
    salesFolder.Folders.Add(customersFolder)
    salesFolder.Folders.Add(contactsFolder)
    salesFolder.Folders.Add(ordersFolder)

    ‘ Add Sales folder to Root Folder
    rootFolder.Folders.Add(salesFolder)

    ‘ Add Root Folder to the Solution Module component
    AdxolSolutionModule1.Folders.Add(rootFolder)

    ‘—————————————————————————
    ‘ Get the default sore name
    Dim [nameSpace] As Outlook.NameSpace = OutlookApp.GetNamespace(“MAPI”)
    Dim store As Outlook.Store = [nameSpace].DefaultStore
    Dim defaultStore As String = store.DisplayName
    Marshal.ReleaseComObject(store)
    Marshal.ReleaseComObject([nameSpace])

    ‘ Add item to Forms Manager Collection
    Dim northwindFormItem As New AddinExpress.OL.ADXOlFormsCollectionItem()
    northwindFormItem.FormClassName = “ADXSolutionsModule.MyForm”
    northwindFormItem.ExplorerLayout = AddinExpress.OL.ADXOlExplorerLayout.WebViewPane
    northwindFormItem.FolderName = defaultStore & “\\Northwind”
    AdxOlFormsManager1.Items.Add(northwindFormItem)

    ‘—————————————————————————

    ‘ Dim northwindformitem As AddinExpress.OL.ADXOlFormsCollectionItem = New AddinExpress.OL.ADXOlFormsCollectionItem
    ‘ northwindformitem.FormClassName = “ADXSolutionsModule.MyForm” ‘ “ADXSolutionsModule.ADXOlForm1”
    ‘ northwindFormItem.ExplorerLayout = AddinExpress.OL.ADXOlExplorerLayout.WebViewPane
    ‘ northwindFormItem.FolderName = defaultStore + “\\Northwind”
    ‘ AdxOlFormsManager1.Items.Add(northwindFormItem)

    Dim contactsFormItem As New AddinExpress.OL.ADXOlFormsCollectionItem()
    contactsFormItem.FormClassName = “ADXSolutionsModule.Myform”
    contactsFormItem.ExplorerLayout = AddinExpress.OL.ADXOlExplorerLayout.WebViewPane
    contactsFormItem.FolderName = defaultStore & “\\Northwind\\Sales\\Contacts”
    AdxOlFormsManager1.Items.Add(contactsFormItem)

  • Pieter van der Westhuizen says:

    Hi Dritan,

    Your code looks ok. I think best thing would be if i look at your project.
    I’ve sent you an e-mail, where you can send your project to.

  • Max says:

    Hi Pieter,
    Is it possible when you create a folder for the Solution Module they does not appear in the default profile? I need that they were in a different user store.

  • Pieter van der Westhuizen says:

    Hi Max,

    Yes, you can change the default root folder of the Solutions module by using the ParentFolderRequestEx event of the Solutions Module object. e.g:

    private void adxolSolutionModule1_ParentFolderRequestEx(object sender, ADXOLParentFolderRequestEventArgs e)
    {
    Outlook.MAPIFolder solutionFolder = null;

    string folderPath = @”\Default Folder(1)”;
    solutionFolder = FolderHelper.GetFolder(folderPath, this.OutlookApp);

    if (solutionFolder != null)
    {
    e.ParentFolder = solutionFolder;
    }
    }

  • Max says:

    Excellent, thanks!

  • Daniel says:

    Hello,

    I am trying to do this tutorial and when adding a form, my VisualStudio 2013 does not. It allows me to select the ADXOlForm1.vb but when I click add, the window disappears and reappears. It is as if it does not supports this component. No error message is displayed.

    Thank you for helping me.
    Daniel

  • Dmitry Kostochko (Add-in Express Team) says:

    Hi Daniel,

    It seems that some exception occurred when you were trying to add a new Outlook region (ADXOlForm1.vb) to your project. May it be that your project is read-only, say it is checked in some source version control software?

  • Daniel says:

    Hi Dmitry,

    No, the project is not connected to a source control. I downloaded the archive of your project. It works well, but can not add a form. As if the component was not made for this project. A kind of forbidden. By controntre, I can add another component that is not a form.

    Do you think that is VisualStudio 2013 that causes this problem?

    Thank you venry much for your help.
    Daniel

  • Daniel says:

    Hello,

    I just did a test with VisualStudio 2010 and I still have the same problem. Unable to add a form to the project. Someone already encounter the same problem as me?

    Thank you!
    Daniel

  • Dmitry Kostochko (Add-in Express Team) says:

    Daniel,

    The sample project you have downloaded is written in C#. Please do not change the file name extension from .cs to .vb when you add a new Outlook region to this project.

  • Daniel says:

    Hi Dmitry,

    I do not change the extension. I thought that maybe the C # project work normally.

    Is it possible to have this code in VB? I could make the worst copy and paste forms already added to the project.

    Thank you!
    Daniel

  • Dmitry Kostochko (Add-in Express Team) says:

    Hi Daniel,

    I have just created a VB.NET version of this code. Please see the download link under the “Available downloads” section.

  • Daniel says:

    Thank you Dmitry for the code VB.NET version.

  • Daniel says:

    Hello,

    Is it possible to make a screen without it being a task display, email, or other?

    I have a folder that points on a screen (panel) where I could develop an application form etc..

    Thank you!
    Daniel

  • Pieter van der Westhuizen says:

    Hi Daniel,

    It sound like you have something like the WebView region in mind. Take a look at Ty’s article here and let us know if this is what you’re looking for.

    Good luck!

  • Laura Lorenz says:

    Hello,

    is there a possibility to remove a solution folder once it has been added as a solution folder? If the user decides to remove my plugin, I would like to remove the folder, too, so that it won’t appear after a restart of Outlook.
    Even worse, when the user decides to add the plugin again, when it has already been installed and removed in a session, she gets an exception message which says that the folder has already been added. I am able to handle this exception in the OnError event, but then my addin doesn’t get loaded completely..

    Thank you!
    Laura

  • Pieter van der Westhuizen says:

    Hi Laura,

    The folder(s) the solution module creates are normal Outlook folders. Normally they’re created under the Default Store’s root folder.
    So you should be able to get a reference to the solution folder and remove them via code.

    Then when the user unregister your add-in, you could try removing the folder in the BeforeUninstallControls event or when they re-install the add-in first check whether the folders exist and then remove them before creating the solution module.

    Hope this makes sense, please let me know if you need more detail.

  • Laura Lorenz says:

    Hi Pieter,

    thanks for your answer. Unfortunately, if I try to remove the folder, I’ll get an exception saying that I don’t have the rights to remove the folder. You can also see this when you have a registered solution and try to remove the folder via right click – it’s disabled.
    As a solution module is an ordinary folder, the user can move for example mails in it. We would like to use this as a feature, so we can’t always delete the folder when unregistering the addin. Is there another way to get around the exception when adding the solution a second time?

  • Pieter van der Westhuizen says:

    Hi Laura,

    Can you please send me a sample project?
    You can find our support e-mail in the readme.txt file in the Add-in Express for .NET folder.

  • Laura Lorenz says:

    Ah ok, now I got your point :) You are correct, I can remove the folder in the BeforeUninstallControls event when unregistering the addin. Thanks for the hint!

    I always just tried to disable the addin via the Outlook Com-Addins-Overview… There is probably no way to delete it here?

    Besides, is there a possibility to check whether there are other solutions installed?

  • Pieter van der Westhuizen says:

    Hi Laura,

    You could try and check for other solutions by using the GetNavigationModule method of the Outlook.NavigationModules object.

    Outlook.Explorer explorer = OutlookApp.ActiveExplorer();
    Outlook.NavigationPane navPane = explorer.NavigationPane;
    Outlook.NavigationModules navModules = navPane.Modules;
    Outlook.SolutionsModule solModule = navModules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleSolutions) as Outlook.SolutionsModule;

    Hope this helps!

  • Francisco Flores says:

    Hi guys

    Is it possible to navigate to a custom Solution Module programmatically? I have Outlook 2013 and I have this code that kind of does that but it enables the Folders view where I can see my Regular Outlook folders (plus the folder associated to the Solution Module) but I would like to see the Folders of my Solution Module only as I had clicked on the Navigation Pane.

    Outlook.MAPIFolder customFolder = GetCustomFolder();
    OutlookApp.ActiveExplorer().CurrentFolder = customFolder;

  • Pieter van der Westhuizen says:

    Hi Francisco,

    You can activate the Solutions Module by using a combination of the Outlook NavigationPane and NavigationModules objects.

    Try the following code to activate your Solution Module:

    Outlook.Explorer currExplorer = null;
    Outlook.NavigationPane navPane = null;
    Outlook.NavigationModules navModules = null;
    Outlook.NavigationModule navModule = null;

    try
    {
    currExplorer = OutlookApp.ActiveExplorer();
    navPane = currExplorer.NavigationPane;
    navModules = navPane.Modules;
    navModule = navModules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleSolutions);
    navPane.CurrentModule = navModule;
    }
    finally
    {
    if (navModule != null) Marshal.ReleaseComObject(navModule);
    if (navModules != null) Marshal.ReleaseComObject(navModules);
    if (navPane != null) Marshal.ReleaseComObject(navPane);
    if (currExplorer != null) Marshal.ReleaseComObject(currExplorer);
    }

    Hope this help!

  • Francisco Flores says:

    Wow! Yes!, I does help! Thank you so much for your quick response!!

  • Maickol Hernandez says:

    Hi Pieter

    Hope you could help me with the following issue. When running the Add-In in my development machine Outlook Form show the information/data/controls in it but when I deploy the app the information is not being shown? Any exception is being throw by the AddIn but when I navigate to the folder nothing happens.

    Thank you

  • Andrei Smolin (Add-in Express Team) says:

    Hello Maickol,

    I assume the issue is now solved. If this isn’t so or if you have any questions, please contact me by email.

Post a comment

Have any questions? Ask us right now!