Display selected items in the active Explorer
This example shows how to use the OutlookItem helper class to conveniently display all the items selected in the active Explorer window.
Example
Note
The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007.
The Selection object contains the set of Outlook items currently selected in the active Outlook explorer. Neither the active explorer, represented by ActiveExplorer(), nor the set of selected items indicates the type of the items that are selected. Normally, you would have to first identify the item type and then call the specific Display method for that type. Because the Display method is common to all Outlook items objects and the OutlookItem helper class includes this method, you can take advantage of the helper class, by declaring an instance of the OutlookItem object, myItem, and using myItem.Display to display each item in the selection. You can see the implementation of the OutlookItem helper class in Create a Helper Class to Access Common Outlook Item Members
If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.
using Outlook = Microsoft.Office.Interop.Outlook;
private void DisplaySelectedItems()
{
Outlook.Selection selection =
Application.ActiveExplorer().Selection;
for (int i = 1; i <= selection.Count; i++)
{
OutlookItem myItem = new OutlookItem(selection[i]);
myItem.Display();
}
}