我正在尝试使用c#Windows应用程序为Outlook创建API。为此,要获取所有AppointmentItem,我正在使用下面的代码,它正在工作。
Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
Microsoft.Office.Interop.Outlook.MAPIFolder Inbox = null;
Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;
oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace("MAPI"); ;
mapiNamespace.Logon("", "",true, true);
CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
CalendarFolder = oApp.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
DateTime startTime = DateTime.Now;
DateTime endTime = startTime.AddDays(5);
//string filter = "[Start] >= '" + startTime.ToString("g") + "' AND [End] <= '" + endTime.ToString("g") + "'";
outlookCalendarItems = CalendarFolder.Items;
// outlookCalendarItems.Restrict(filter);
// outlookCalendarItems.Sort("Start");
outlookCalendarItems.IncludeRecurrences = true;
int i = 0;
foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{
dataGridCalander.Rows.Add();
dataGridCalander.Rows[i].Cells[0].Value = i + 1;
if (item.Subject != null)
{
dataGridCalander.Rows[i].Cells[1].Value = item.Subject;
}
}
类似地,我要获得在特定会议室的外观和状态中创建的可用会议室(是否可用)。提前致谢。
我注意到以下代码行:
foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
不要遍历循环中的所有Outlook项目。使用“查找/查找下一个”或“限制”方法来查找所需的子集。
或使用Folder类的GetTable方法获得一个Table对象,该对象包含由Filter过滤的项目。如果Filter为空字符串或省略Filter参数,则GetTable返回一个Table,其中的行表示Folder中的所有项目。如果Filter为空字符串或省略Filter参数且TableContents为olHiddenItems,则GetTable返回一个Table,其中的行表示Folder中的所有隐藏项。
Sub DemoTable()
'Declarations
Dim Filter As String
Dim oRow As Outlook.Row
Dim oTable As Outlook.Table
Dim oFolder As Outlook.Folder
'Get a Folder object for the Inbox
Set oFolder = Application.Session.GetDefaultFolder(olFolderInbox)
'Define Filter to obtain items last modified after May 1, 2005
Filter = "[LastModificationTime] > '5/1/2005'"
'Restrict with Filter
Set oTable = oFolder.GetTable(Filter)
'Enumerate the table using test for EndOfTable
Do Until (oTable.EndOfTable)
Set oRow = oTable.GetNextRow()
Debug.Print (oRow("Subject"))
Debug.Print (oRow("LastModificationTime"))
Loop
End Sub
Outlook对象模型不为房间提供任何方法或属性。您可以使用Namespace类的OpenSharedFolder方法打开房间的共享日历。
考虑改用EWS。有关更多信息,请参见Exchange中的EWS托管API,EWS和Web服务。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句