Dimitry,
It doesn't make any difference. I coded it exactly in the same order
as
the
VBA and same result. When I grant myself Editor permissions on the
other
user's calendar the date of the recurring items is that of the actual
occurence. When I have simply Reviewer permissions, then the start
date
is
that of the master appointment not the actual occurence.
Tad
-----------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;
namespace ConsoleApplication1
{
public partial class Program
{
static void Main(string[] args)
{
bool Foobar = false;
Foobar = GetAppointments();
}
private static bool GetAppointments()
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
Outlook.AppointmentItem oAppt = null;
int intFoo = 0;
//create recipient
Outlook.Recipient oRcp =
oNS.CreateRecipient("(e-mail address removed)");
//Get calendar info (appointments)
Outlook.MAPIFolder oFdr = oNS.GetSharedDefaultFolder(oRcp,
Outlook.OlDefaultFolders.olFolderCalendar);
if (oFdr != null)
{
Outlook.Items oItms = (Outlook.Items)oFdr.Items;
oItms.Sort("[Start]", false);
oItms.IncludeRecurrences = true; //blnIncludeRecurrences;
oItms.Sort("[Start]", false);
string strFilter = "([End] > \"September 1, 2006 12:00 AM\"
AND
[Start] <= \"March 1, 2007 12:00 AM\")";
Outlook.Items oApps = oItms.Restrict(strFilter);
try
{
oAppt = (Outlook.AppointmentItem)oApps.GetFirst();
intFoo = (int)oAppt.Class;
}
catch
{
intFoo = 0;
}
if (intFoo == 26)
{
while (oAppt != null)
{
System.Windows.Forms.MessageBox.Show("Subject = " +
oAppt.Subject + " Start = " + oAppt.Start.ToString("MMM dd, yyyy
HH:mm"));
oAppt = (Outlook.AppointmentItem)oApps.GetNext();
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
}
:
The major difference is that in VB you call Sort, then Restrict. In C#
you
have it the other way around and you call Sort on oApps, not oItms .
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Dmitry,
Here's the C# code that Ken and I have both tested. In his case, he
got
the
correct date for each recurrence but I don't know the permissions he
had.
In
my case with reviewer permissions I did not get the right date for
each
occurence, I just got the master start date. Below is the VBA code.
using System;
using System.Collections.Generic;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;
namespace ConsoleApplication1
{
public partial class Program
{
static void Main(string[] args)
{
bool Foobar = false;
Foobar = GetAppointments();
}
private static bool GetAppointments()
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
Outlook.AppointmentItem oAppt = null;
int intFoo = 0;
//create recipient
Outlook.Recipient oRcp =
oNS.CreateRecipient("(e-mail address removed)");
//Get calendar info (appointments)
Outlook.MAPIFolder oFdr = oNS.GetSharedDefaultFolder(oRcp,
Outlook.OlDefaultFolders.olFolderCalendar);
if (oFdr != null)
{
Outlook.Items oItms = (Outlook.Items)oFdr.Items;
oItms.IncludeRecurrences = true;
string strFilter = "([End] > \'September 1, 2006 12:00
AM\'
AND
[Start] <= \'March 1, 2007 12:00 AM\')";
Outlook.Items oApps = oItms.Restrict(strFilter);
oApps.Sort("[Start]", false);
oApps.IncludeRecurrences = true; //blnIncludeRecurrences;
try
{
oAppt = (Outlook.AppointmentItem)oApps.GetFirst();
intFoo = (int)oAppt.Class;
}
catch
{
intFoo = 0;
}
if (intFoo == 26)
{
while (oAppt != null)
{
System.Windows.Forms.MessageBox.Show("Subject = "
+
oAppt.Subject + " Start = " +
oAppt.Start.ToString("MMM dd, yyyy HH:mm"));
oAppt = (Outlook.AppointmentItem)oApps.GetNext();
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
}
Here's the VBA code:
Sub GetRecipientAppointments
Dim oRcp As Outlook.recipient
Dim oFdr As Outlook.MAPIFolder
Dim oItms As Outlook.Items
Dim oAItms As Outlook.Items
Dim oAItm As Object
Dim datStart As Date
Dim datEnd As Date
Dim datRecent As Date
Dim strFind As String
Set oApp = Application
Set oNS = oApp.GetNamespace("MAPI")
Set oAL = oNS.AddressLists("Global Address List")
Set oRcp = oNS.CreateRecipient(dubya@exchange_whitehouse.gov)
'Get recipient calendar info
On Error Resume Next
Set oFdr = oNS.GetSharedDefaultFolder(oRcp, olFolderCalendar)
On Error GoTo 0
If oFdr Is Nothing Then
Debug.Print recipient & " -- access denied --"
Else
Set oItms = Nothing
Set oItms = oFdr.Items
oItms.SetColumns
("Subject,Start,End,BusyStatus,LastModificationTime,IsRecurring")
oItms.Sort "[Start]", False
oItms.IncludeRecurrences = True
oItms.Sort "[Start]", False
datStart = DateSerial(Year(Date), Month(Date), 1)
datEnd = DateAdd("m", 2, datStart)
datRecent = DateAdd("m", -1, datStart)
strFind = "([End] > " & Quote(Format(datStart, "mmmm d, yyyy
hh:mm
AMPM")) & " AND [Start] <= " & Quote(Format(datEnd, "mmmm d, yyyy
hh:mm
AMPM")) & ") "
'strFind = "[Start] > " & Quote(Format(datStart, "mmmm d, yyyy
hh:mm
AMPM"))
'Set oAItm = oItms.Find(strFind) '(strFind)
Set oAItms = oItms.Restrict(strFind)
For Each oAItm In oAItms
Debug.Print oAItm.Start & " " & oAItm.End & " " &
oAItm.Subject
'Set oAItm = oItms.FindNext
Next
End If
Set oFdr = Nothing
End Sub
Function Quote(MyText)
Quote = Chr(34) & MyText & Chr(34)
End Function
:
Outlook does not know or care whether you are acessing it using VB
or
C#.
I
don't even think there is way to know even if it wanted to.
Do you have sample code snippets in both VBA and C# that demostrate
this
behavior?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
If you sort calendar items by start date and set
IncludeRecurrences=true
you
can retrieve the individual occurences of recurring appointments
in
other
users' calendars. I have been able to code this in both VBA and
C#.
However, there appears to be a difference in how the two
implementations
work. In VBA I only need Reviewer permissions to retrieve the
individual
occurences but in C# I need Editor permissions - otherwise, I get
an
instance
of each individual occurence but the start date is that of the
master
appointment rather than the occurence.
Can anyone shed some light on this please?
Thanks, Tad