MindFusion.Wpf Pack Programmer's Guide
Tutorial 7: Exchanging Data with Microsoft Outlook

This tutorial demonstrates how to import and export Scheduling for WPF event information from/to Microsoft® Outlook®.

1. Create and initialize a new WPF application project

Follow steps 1 through 3 from Tutorial 1: Getting Started.

Set CurrentView to WeekRange, Date to Jan 1, 2010 and EndDate to Mar 1, 2010, respectively.

2. Add a reference to the Outlook library

Go to the 'Solution Explorer' window. You can show this window by selecting View -> Solution Explorer from the menu. Find the 'References' node in the tree view displayed in the 'Solution Explorer', right-click on it with the mouse and select 'Add Reference...' from the context menu that appears. In the "Add reference" dialog click the 'Browse...' button and navigate to the Outlook Import/Export library - MindFusion.Scheduling.Outlook.dll. This file is usually found in the 'c:\Program Files\MindFusion\MindFusion.Scheduling for WPF' folder or in the folder where you have installed the product. Click the 'OK' button to add the assembly reference to your project.

 Note

In Visual Basic projects you will have to check the 'Show All Files' button in the Solution Explorer toolbar in order for the References project item to appear.

3. Import the necessary namespaces

Include the MindFusion.Scheduling and MindFusion.Scheduling.Outlook namespaces in the beginning of the file. These namespaces contain all schedule classes along with the OutlookImporter and OutlookExporter classes, which provide Outlook Export/Import capabilities.

C#  Copy Code

using MindFusion.Scheduling;
using MindFusion.Scheduling.Outlook;

Visual Basic  Copy Code

Imports MindFusion.Scheduling
Imports MindFusion.Scheduling.Outlook

4. Add import and export buttons to the form

Add two buttons to the form, named _btnImport and _btnExport accordingly. Set the texts of the buttons to 'Import' and 'Export' respectively. Create a Click event handler for each of those buttons by double-clicking on the buttons in the design environment.

The body of the event handler of the 'Import' button should look like this:

C#  Copy Code

private void _btnImport_Click(object sender, RoutedEventArgs e)
{
    OutlookImporter importer = new OutlookImporter(calendar.Schedule);
    importer.ImportItems();
}

Visual Basic  Copy Code

Private Sub _btnImport_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

   Dim importer As OutlookImporter = New OutlookImporter(calendar.Schedule)
   importer.ImportItems()

End Sub

The code above creates a new instance of the OutlookImporter class, passing to the constructor a reference to the Schedule object, which will be the target of the importing operation. Then it calls the ImportItems method of the OutlookImporter class in order to import all items from Outlook to the specified schedule. More complicated scenarios are possible. For example you can filter certain items during the importing process by attaching a handler to the ItemImporting event of the OutlookImporter class.

The body of the event handler of the 'Export' button will look similarly.

C#  Copy Code

private void _btnExport_Click(object sender, RoutedEventArgs e)
{
    OutlookExporter exporter = new OutlookExporter(calendar.Schedule);
    exporter.ExportItems();
}

Visual Basic  Copy Code

Private Sub _btnExport_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

   Dim exporter As OutlookExporter = New OutlookExporter(calendar.Schedule)
   exporter.ExportItems()

End Sub

5. Build and run

Compile and run the application. Click the 'Import' button to import all items from Outlook into out application. Click the 'Export' button to export all items from the application to Outlook.