September 2003
Intermediate to advanced
624 pages
14h 27m
English
You want to use ADO.NET to extract data from Microsoft Outlook or Microsoft Exchange.
Use the OLE DB Jet provider to access Exchange and Outlook data.
The sample code contains two event handlers:
Form.LoadDisplays a form that allows the user to specify the mailbox name and mail profile to connect to.
Button.ClickCreates and opens a connection to Outlook or Exchange data using the
OLE DB .NET data provider. A DataAdapter is used
to fill a table with the Subject and
Content of each message in the
Inbox. The default view of the table is
bound to a data grid on the form.
The C# code is shown in Example 1-8.
Example 1-8. File: ConnectExchangeDataForm.cs
// Namespaces, variables, and constants using System; using System.Windows.Forms; using System.Data; using System.Data.OleDb; // . . . private void ConnectExchangeDataForm_Load(object sender, System.EventArgs e) { mailboxNameTextBox.Text = "Personal Folders"; profileTextBox.Text = "Outlook"; } private void connectButton_Click(object sender, System.EventArgs e) { String sqlText = "SELECT Subject, Contents FROM Inbox"; // Build the connection string. String connectionString="Provider=Microsoft.Jet.OLEDB.4.0;" + "Outlook 9.0;" + "MAPILEVEL=" + mailboxNameTextBox.Text + "|;" + "PROFILE=" + profileTextBox.Text + ";" + "TABLETYPE=0;" + "DATABASE=" + System.IO.Path.GetTempPath( ); // Create the DataAdapter. OleDbDataAdapter da = new OleDbDataAdapter(sqlText, connectionString); // Create ...Read now
Unlock full access