【问题标题】:Outlook API to get meeting details in c#Outlook API 在 C# 中获取会议详细信息
【发布时间】:2015-03-31 19:36:41
【问题描述】:

我正在尝试使用 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;
                } 
}

类似的方式,我想获取在 Outlook 中创建的可用会议室以及该特定会议室的状态(可用或不可用)。提前致谢。

【问题讨论】:

    标签: c# outlook


    【解决方案1】:

    我注意到下面这行代码:

     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 将返回一个 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。请参阅EWS Managed API, EWS, and web services in Exchange 了解更多信息。

    【讨论】:

    • 感谢您的回答。是否有可能获得可用的资源?
    猜你喜欢
    • 2018-08-04
    • 2014-10-15
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 2016-09-24
    相关资源
    最近更新 更多