You shouldn't need to use NameSpace.Logon. And you should create your
appointment in that folder using the Add method. You're able to log into
that mailbox using that Recipient object? That object should have
permissions at minimum allowing creation of new items in that folder. See if
something like this works:
// Create a OOM reference
outlook.Application outApp = new
Microsoft.Office.Interop.Outlook.Application();
// Create a new meeting object
//outlook._AppointmentItem mtg =
(outlook._AppointmentItem)outApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
// Acquire the namespace
outlook.NameSpace ns = outApp.GetNamespace("MAPI");
// Logon to the namespace
// ns.Logon("exchange", Missing.Value, false, true);
// Create a receipient object that is going to be the
organizer of the meeting
outlook.Recipient r = ns.CreateRecipient("Controller,
Project");
r.Resolve();
// Open the shared calendar for this receipient
outlook.MAPIFolder f = ns.GetSharedDefaultFolder(r,
Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
outlook._AppointmentItem mtg = (outlook._AppointmentItem)
f.Items.Add(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
// Setup the requirements for the meeting
mtg.MeetingStatus =
Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
mtg.Location = "Meeting Room";
// Add the other meeting attendee(s)
outlook.Recipient rec1 = mtg.Recipients.Add("James,
Jason");
rec1.Type =
(int)outlook.OlMeetingRecipientType.olRequired;
mtg.Subject ="Test meeting";
mtg.Start = new DateTime(2007, 9, 20, 15, 0, 0);
mtg.Duration = 60;
mtg.Body = "This is just a test meeting from C#";
mtg.ReminderMinutesBeforeStart = 60;
mtg.ReminderSet = true;
try
{
System.Diagnostics.Debug.WriteLine("There are " +
f.Items.Count + " items in the calendar.");
mtg.Save();
// mtg.Organizer is null and an exception is raised
//System.Diagnostics.Debug.WriteLine("The meeting
organizer is : " + mtg.Organizer.ToString());
// Add the meeting item to the folder.
// f.Items.Add(mtg);
}
catch (ArgumentException ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message.ToString());
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message.ToString());
}
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Jason James" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ken,
>
> thanks for your thoughts. I have implemented that I think you are
> suggesting, although I have no real experience with namespaces.
>
> Here is what I ended up with:
>
> // Create a OOM reference
> outlook.Application outApp = new
> Microsoft.Office.Interop.Outlook.Application();
> // Create a new meeting object
> outlook._AppointmentItem mtg =
> (outlook._AppointmentItem)outApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
>
> // Acquire the namespace
> outlook.NameSpace ns = outApp.GetNamespace("MAPI");
> // Logon to the namespace
> ns.Logon("exchange", Missing.Value, false, true);
>
> // Create a receipient object that is going to be the
> organizer of the meeting
> outlook.Recipient r = ns.CreateRecipient("Controller,
> Project");
> // Open the shared calendar for this receipient
> outlook.MAPIFolder f = ns.GetSharedDefaultFolder(r,
> Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
>
> // Setup the requirements for the meeting
> mtg.MeetingStatus =
> Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
> mtg.Location = "Meeting Room";
> // Add the other meeting attendee(s)
> outlook.Recipient rec1 = mtg.Recipients.Add("James,
> Jason");
> rec1.Type =
> (int)outlook.OlMeetingRecipientType.olRequired;
>
> mtg.Subject ="Test meeting";
> mtg.Start = new DateTime(2007, 9, 20, 15, 0, 0);
> mtg.Duration = 60;
> mtg.Body = "This is just a test meeting from C#";
> mtg.ReminderMinutesBeforeStart = 60;
> mtg.ReminderSet = true;
>
> try
> {
> System.Diagnostics.Debug.WriteLine("There are " +
> f.Items.Count + " items in the calendar.");
>
> // mtg.Organizer is null and an exception is raised
> //System.Diagnostics.Debug.WriteLine("The meeting
> organizer is : " + mtg.Organizer.ToString());
> // Add the meeting item to the folder.
> f.Items.Add(mtg);
> }
> catch (ArgumentException ex)
> {
>
> System.Diagnostics.Debug.WriteLine(ex.Message.ToString());
> }
> catch (Exception ex)
> {
>
> System.Diagnostics.Debug.WriteLine(ex.Message.ToString());
> }
>
>
> However, when I execute the code an exception is thrown when I try and
> add the appointment to the shared calendar.
>
> A first chance exception of type 'System.ArgumentException' occurred
> in MS Project Automation.exe
> Could not complete the operation. One or more parameter values are not
> valid.
>
> Is there anything wrong with my implementation of your suggestion or
> anything else I should be trying?
>
> Thanks for your help on this,
>
> Jason.
>