2015-03-31 244 views
1

我正在嘗試使用c#windows應用程序爲Outlook創建API。爲此,要獲取所有AppointmentItem,我使用下面的代碼並且它正在工作。Outlook API在c#中獲取會議詳細信息#

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; 
       } 
} 

類似的方式,我想獲得的前景和特定的會議室狀態(可用與否)創建可用的會議室。提前致謝。

回答

0

我已經注意到下面的代碼行:

foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems) 

不要遍歷迴路中的所有Outlook項目。使用Find/FindNext或Restrict方法查找所需的子集。

或者使用Folder類的GetTable方法獲得一個Table對象,該對象包含由Filter過濾的項目。如果Filter是空字符串或省略了Filter參數,則GetTable會返回一個表格,其中的行將表示文件夾中的所有項目。如果Filter是空字符串或者省略了Filter參數並且TableContents是olHiddenItems,則GetTable會返回一個表格,其中的行代表文件夾中的所有隱藏項目。

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對象模型不提供任何房間的方法或屬性。您可以使用名稱空間類的OpenSharedFolder方法打開房間的共享日曆。

請考慮使用EWS。有關更多信息,請參閱EWS Managed API, EWS, and web services in Exchange

+0

感謝您的回答。是否有可能獲得資源? – 2015-03-31 11:53:07