Outlook Termine exportieren
Frank Dzaebel, erstellt am: 19.2.2006, zuletzt geändert: 19.2.2006
Kategorie: Office, .NET-Version: 2.0, [Download]
Hier wird beschrieben, wie man Outlook Termine über Automation in einen DataTable füllt, um die Daten dann in einem DataGridView anzuzeigen.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookExport
{
public partial class Form1 : Form
{
public Form1() {InitializeComponent();}
private void button1_Click(object sender,EventArgs e)
{
DateTime vonDatum = dtpVon.Value;
DateTime bisDatum = dtpBis.Value;
Outlook.Application outlook = new Outlook.Application();
Outlook.NameSpace objNamespace = outlook.GetNamespace("MAPI");
objNamespace.Logon(null,null,true,true);
DataSet importCalendarItems = new DataSet();
importCalendarItems.DataSetName = "calendar";
DataTable dt = importCalendarItems.Tables.Add("Appointment");
string[] cols = {"Subject","Location","Start","End","AllDayEvent",
"Duration","Organizer","Importance","Sensitivity","Body"};
foreach (string col in cols) dt.Columns.Add(col);
Outlook.MAPIFolder objFolder = objNamespace.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderCalendar);
foreach (object item in objFolder.Items)
{
Outlook.AppointmentItem appItem = item as Outlook.AppointmentItem;
if (appItem == null) continue;
DateTime itemDate = appItem.Start;
if (appItem.Start >= vonDatum && appItem.Start <= bisDatum)
{
importCalendarItems.Tables[0].Rows.Add(new object[] {
appItem.Subject, appItem.Location, appItem.Start,appItem.End,
appItem.AllDayEvent,appItem.Duration, appItem.Organizer,
appItem.Importance, appItem.Sensitivity, appItem.Body});
}
}
dataGridView1.DataSource = dt;
}
private void Form1_Load(object sender,EventArgs e)
{
dtpVon.Value = DateTime.Now.AddDays(-30);
dtpBis.Value = DateTime.Now;
}
}
}