I am trying to create an API for outlook using c# windows app. For that , to get all the AppointmentItem I am using the below code and it is working.
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;
}
}
Similar way , I want get the available meeting rooms created in outlook and status of that particular meeting rooms (available or not) . Thanks in Advance.
I have noticed the following line of code:
foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
Don't iterate over all Outlook items in the loop. Use the Find/FindNext or Restrict methods to find the required subset.
Or use the GetTable method of the Folder class which obtains a Table object that contains items filtered by Filter. If Filter is a blank string or the Filter parameter is omitted, GetTable returns a Table with rows representing all the items in the Folder. If Filter is a blank string or the Filter parameter is omitted and TableContents is olHiddenItems, GetTable returns a Table with rows representing all the hidden items in the 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
The Outlook object model doesn't provide any method or property for rooms. You can use the OpenSharedFolder method of the Namespace class to open a shared calendar for a room.
Consider using EWS instead. See EWS Managed API, EWS, and web services in Exchange for more information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.