0
,當我寫了這個代碼,我有兩個問題是:慢的代碼連接到Outlook日曆
- 它太慢
- 它僅顯示在日曆中定期約會。我希望它不僅顯示來自特定日期的定期約會,還顯示該日期以及從指定日期開始的所有其他約會。
幫助將不勝感激。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void GetAllCalendarItems()
{
try
{
// outlook application object
Outlook.Application oApp = new Outlook.Application();
//folder in outlook
Outlook.Folders OutlookFolders = oApp.Session.Folders;
//Mapi folder object
Outlook.MAPIFolder Folder = null;
// outlook exploer object
Outlook.Explorer explorer = null;
//Map subfolder object
Outlook.MAPIFolder SubFolder = null;
// folder int control
int Folderctr;
// sub folder control
int subFolderctr;
// initialize base objects
//date range to get appointments
DateTime start = DateTime.Now;
DateTime end = start.AddDays(5);
// loop throught the PST files added on Outlook
for (Folderctr = 1; Folderctr <= OutlookFolders.Count; Folderctr++)
{
Folder = OutlookFolders[Folderctr];
Console.WriteLine("first name of folder " +Folder.Name);
explorer = Folder.GetExplorer();
//loop throught the folders in the PST files
for (subFolderctr = 1; subFolderctr <= explorer.CurrentFolder.Folders.Count; subFolderctr++)
{
SubFolder = explorer.CurrentFolder.Folders[subFolderctr];
if (SubFolder.Name == "SCE_Calendar")
{
GetAllCalendarItems(SubFolder);
Console.WriteLine("subfolder name of folder " + SubFolder.Name);
}
}
}
//close applciation
oApp.Quit();
// release com object
System.Runtime.InteropServices.Marshal.ReleaseComObject(oApp);
oApp = null;
}
//Simple error handling.
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
public void GetAllCalendarItems(Outlook.MAPIFolder seCal)
{
Outlook.Items outlookCalendarItems = null;
//set recursion to true
outlookCalendarItems = seCal.Items;
outlookCalendarItems.IncludeRecurrences = true;
DateTime last;
DateTime first;
foreach (Outlook.AppointmentItem item in outlookCalendarItems)
{
Outlook.RecurrencePattern rp = item.GetRecurrencePattern();
first = new DateTime(2012, 2, 1, item.Start.Hour, item.Start.Minute, 0);
last = new DateTime(2012, 2, 29);
Outlook.AppointmentItem recur = null;
for (DateTime cur = first; cur <= last; cur = cur.AddDays(1))
{
try
{
recur = rp.GetOccurrence(cur);
//Console.WriteLine(recur.Subject + " -> " + cur.ToLongDateString());
Console.WriteLine("Subject: " + recur.Body);
Console.WriteLine("Organizer: " + recur.Organizer);
Console.WriteLine("Start: " + recur.Start.ToString());
Console.WriteLine("End: " + recur.End.ToString());
Console.WriteLine("Location: " + recur.Location);
Console.WriteLine("Recurring: " + recur.IsRecurring);
Console.WriteLine("-----------------------------------------");
Console.WriteLine(" ");
//Show the item to pause.
}
catch
{ }
}
}
}
private void button1_Click(object sender, EventArgs e)
{
GetAllCalendarItems();
}
}
}
發佈您的所有代碼並尋求幫助改進它並不是一個真正的建設性問題。我會建議提煉您的問題,以顯示導致您遇到問題的代碼部分,並提供您遇到的問題的詳細說明。 – 2012-02-22 15:21:09