共有カレンダーを表示したい。ウェブで検索すると、次のコードが見つかりました。
static void Main(string[] args)
{
Outlook.Application objOLApp;
Outlook.MAPIFolder objFolder;
Outlook.Explorer objExplorer;
Outlook.MAPIFolder objSubFolder;
Outlook.AppointmentItem objCalenderItem;
Outlook.Folders objOutlookFolders;
int intFolderCtr;
int intSubFolderCtr;
int intAppointmentCtr;
// >> Initialize The Base Objects
objOLApp = new Outlook.Application();
objOutlookFolders = objOLApp.Session.Folders;
// >> Loop Through The PST Files Added n Outlook
for (intFolderCtr = 1; intFolderCtr <= objOutlookFolders.Count; intFolderCtr++)
{
objFolder = objOutlookFolders[intFolderCtr];
objExplorer = objFolder.GetExplorer();
// >> Loop Through The Folders In The PST File
for (intSubFolderCtr = 1; intSubFolderCtr <= objExplorer.CurrentFolder.Folders.Count; intSubFolderCtr++)
{
objSubFolder = objExplorer.CurrentFolder.Folders[intSubFolderCtr];
// >> Check if Folder Contains Appointment Items
if (objSubFolder.DefaultItemType == Outlook.OlItemType.olAppointmentItem)
{
// >> Loop Through Appointment Items
for (intAppointmentCtr = 1; intAppointmentCtr <= objSubFolder.Items.Count; intAppointmentCtr++)
{
// >> Get Teh Calender Item From The Calender Folder
objCalenderItem = objSubFolder.Items[intAppointmentCtr];
// >> Process Appointment Item Accordingly
Console.WriteLine(objCalenderItem.Subject);
Console.WriteLine(objCalenderItem.Location + "," + objCalenderItem.Start.ToLongDateString());
Console.WriteLine();
Console.WriteLine();
}
}
}
}
// >> Close Application
// objOLApp.Quit();
// >> Release COM Object
System.Runtime.InteropServices.Marshal.ReleaseComObject(objOLApp);
objOLApp = null;
Console.ReadLine();
}
しかし、それは私の予定だけを参照してください。
すべての共有カレンダーを表示したい。会議を設定しましたが、他の人の忙しいか暇なのかわかりません。どうすれば他の人のカレンダーを表示できますか?
編集:
私はこの行を変更しました
objOutlookFolders = objOLApp.Session.Folders;
と
objOutlookFolders = oNs.GetSharedDefaultFolder(oRep, OlDefaultFolders.olFolderCalendar).Folders;
そして私はこれを追加します
NameSpace oNs = objOLApp.GetNamespace("MAPI");
Recipient oRep = oNs.CreateRecipient(objOLApp.Session.CurrentUser.Name);
しかし、私はまだエラーが発生します。
新しいバージョンは
static void Main(string[] args)
{
Outlook.Application objOLApp;
Outlook.MAPIFolder objFolder;
Outlook.Explorer objExplorer;
Outlook.MAPIFolder objSubFolder;
Outlook.AppointmentItem objCalenderItem;
Outlook.Folders objOutlookFolders;
int intFolderCtr;
int intSubFolderCtr;
int intAppointmentCtr;
// >> Initialize The Base Objects
objOLApp = new Outlook.Application();
NameSpace oNs = objOLApp.GetNamespace("MAPI");
Recipient oRep = oNs.CreateRecipient(objOLApp.Session.CurrentUser.Name);
oRep.Resolve();
//if (oRep.Resolved)
objOutlookFolders = oNs.GetSharedDefaultFolder(oRep, OlDefaultFolders.olFolderCalendar).Folders;
//else
// objOutlookFolders = objOLApp.Session.Folders;
// >> Loop Through The PST Files Added n Outlook
for (intFolderCtr = 1; intFolderCtr <= objOutlookFolders.Count; intFolderCtr++)
{
objFolder = objOutlookFolders[intFolderCtr];
objExplorer = objFolder.GetExplorer();
// >> Loop Through The Folders In The PST File
for (intSubFolderCtr = 1; intSubFolderCtr <= objExplorer.CurrentFolder.Folders.Count; intSubFolderCtr++)
{
objSubFolder = objExplorer.CurrentFolder.Folders[intSubFolderCtr];
// >> Check if Folder Contains Appointment Items
if (objSubFolder.DefaultItemType == Outlook.OlItemType.olAppointmentItem)
{
// >> Loop Through Appointment Items
for (intAppointmentCtr = 1; intAppointmentCtr <= objSubFolder.Items.Count; intAppointmentCtr++)
{
// >> Get Teh Calender Item From The Calender Folder
objCalenderItem = objSubFolder.Items[intAppointmentCtr];
// >> Process Appointment Item Accordingly
Console.WriteLine(objCalenderItem.Subject);
Console.WriteLine(objCalenderItem.Location + "," + objCalenderItem.Start.ToLongDateString());
Console.WriteLine();
Console.WriteLine();
}
}
}
}
// >> Close Application
// objOLApp.Quit();
// >> Release COM Object
System.Runtime.InteropServices.Marshal.ReleaseComObject(objOLApp);
objOLApp = null;
Console.ReadLine();
}
私を助けてください..私はまだ働いています。しかし、そうではありませんでした。