Assuming that you're using Visual Studio 2010, you'll most likely start by creating a Visual Studio Tools for Office (VSTO) project to create your add-in. Look here for details on VSTO and Visual Studio.
Once you have that up and running, you will have a source file called ThisAddIn.cs that contains the "main entry point" into your add-in. From there, you can hook into events that Outlook will raise when certain events take place. You will most likely be interested in the following events:
- BeforeFolderSwitch
- FolderSwitch
Your code will look something like this:
private void ThisAddIn_Startup(object sender, EventArgs e)
{
var explorer = this.Application.ActiveExplorer();
explorer.BeforeFolderSwitch += new ExplorerEvents_10_BeforeFolderSwitchEventHandler(explorer_BeforeFolderSwitch);
explorer.FolderSwitch += new ExplorerEvents_10_FolderSwitchEventHandler(explorer_FolderSwitch);
}
/// <summary>
/// Handler for Outlook's "BeforeFolderSwitch" event. This event fires before the explorer goes to
/// a new folder, either as a result of user action or through program code.
/// </summary>
/// <param name="NewlySelectedFolderAsObject">
/// The new folder to which navigation is taking place. If, for example, the user moves from "Inbox"
/// to "MyMailFolder", the new current folder is a reference to the "MyMailFolder" folder.
/// </param>
/// <param name="Cancel">
/// A Boolean describing whether or not the operation should be canceled.
/// </param>
void explorer_BeforeFolderSwitch(object NewlySelectedFolderAsObject, ref bool Cancel)
{
if (NewlySelectedFolderAsObject == null)
return;
var newlySelectedFolderAsMapiFolder = NewlySelectedFolderAsObject as MAPIFolder;
}
void explorer_FolderSwitch()
{
}
Your code should be placed in those event handlers to perform your work.