Adding appointment to Outlook (2013) opens up the meeting editor - c#

I am trying to add appointments to Outlook programmatically.
I ran this code which runs successful but after I save the appointment the meeting editor opens up in outlook.
AppointmentItem appItem = null;
try
{
appItem = outlookItems.Add(OlItemType.olAppointmentItem) as AppointmentItem;
if(appItem == null)
continue;
appItem.Subject = "Subject";
appItem.MeetingStatus = OlMeetingStatus.olMeeting;
appItem.Location = "Location";
appItem.Save();
appItem.Display(true);
}
finally
{
if (appItem != null)
{
Marshal.ReleaseComObject(appItem);
}
}
I tried calling Display(true), Display(false) it still doesn't work.
Please can anyone tell me if I am doing anything wrong.

But you create a new meeting item in the code setting the following property:
appItem.MeetingStatus = OlMeetingStatus.olMeeting;
If you don't want to see a new item window (inspector), there is no need to run the following line of code:
appItem.Display(true);
The Display method displays a new Inspector object for the item.
You may find the Getting Started with VBA in Outlook 2010 article in MSDN helpful.

if the appointment is of type OlMeetingStatus.olMeeting, recipients are supposed to be present.
I changed the type to
appItem.MeetingStatus = OlMeetingStatus.olNonMeeting
and removed the call to display. I was able to save the appointment in the calendar

Related

C# outlook interop saving meeting as appointment issues

I am trying to save an Outllok meeting ics file as an Outlook appointment ics but when i use do SaveAs to a folder location, it is saving as a meeting.
I have the following code but I can not seem to locate the issue. When I use .Display it shows as an appointment but .SaveAs is saving back as a meeting with recipients.
Any help is much appreciated
Outlook.Application App = new Outlook.Application();
string FPath = #"C:\\Documents\TestMeeting.ics"
var item = App.Session.OpenSharedItem(FPath) as Outlook.MeetingItem;
var AppointmentItem = item.GetAsssociatedAppointment(false);
AppointmentItem.MeetingStatus = Outlook.OlMeetingStatus.olNonMeeting;
AppointmentItem.Display(true);
AppointmentItem.SaveAs(#"C:\\Documents\TestAppointment1.ics",Outlook.OlSaveAsType.olIcal);
Use the Save method to save the just opened meeting into your calendar:
string FPath = #"C:\\Documents\TestMeeting.ics"
var item = App.Session.OpenSharedItem(FPath) as Outlook.MeetingItem;
item.Save();
// only after that you can try reprieving the associated appointment
var AppointmentItem = item.GetAsssociatedAppointment(false);
Also I'd recommend creating a new appointment item from scratch and then saving it to the disk.
Thanks Eugene. I managed to get this working by creating a new appointment and using .BodyFormat and .RTFBody of the associated appointment. I have included the full code below for anyone in the future and marked your answer as correct. Apologies but at present I don't have enough rep to upvote otherwise I would. Many thanks
Outlook.Application App = new Outlook.Application();
string FPath = #"C:\\Documents\TestMeeting.ics"
var item = App.Session.OpenSharedItem(FPath) as Outlook.MeetingItem;
var AppointmentItem = item.GetAsssociatedAppointment(false);
Outlook.AppointmentItem ap1 = (Outlook.AppointmentItem)App.CreateItem(Outlook.OlItemType.olAppointmentItem);
ap1.Start = AppointmentItem.Start;
ap1.Subject = AppointmentItem.Subject;
ap1.BodyFormat = AppointmentItem.BodyFormat;
ap1.RTFBody = AppointmentItem.RTFBody;
ap1.Location = AppointmentItem.Location;
ap1.SaveAs(#"C:\\Documents\TestAppointment1.ics",Outlook.OlSaveAsType.olIcal);

How to display HTML content in Outlook.AppointmentItem body in outlook Add-ins

Am trying to display HTML content inside the Outlook Appointment body but am not able to (i tried for both body and FTFbody option). Anyone Please help me . Below is my code .
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application application = Globals.ThisAddIn.Application;
Outlook.Inspector inspector = application.ActiveInspector();
Outlook.AppointmentItem AppointmentItem = inspector.CurrentItem as Outlook.AppointmentItem;
if (AppointmentItem != null)
{
if (AppointmentItem.EntryID == null)
{
string messageBody = string.Empty;
string defaultMessageBody = "Click <a href='https://www.google.com/' > here </a>";
AppointmentItem.Subject = "This text was added by using code";
AppointmentItem.Recipients.Add("testuser1#gmail.com");
AppointmentItem.Location = "INDIA";
//AppointmentItem.RTFBody = System.Text.Encoding.Default.GetBytes(defaultMessageBody);
AppointmentItem.Body = defaultMessageBody;
AppointmentItem.Save();
}
}
}
Firstly, you should not be using Outlook (or any other Office app) under a service (such as ASP.Net).
Secondly, Outlook 2016 and higher supports HTML in appointments, but that support has not been exposed through the Outlook Object Model. You can attempt to set the PR_HTML property (DASL name http://schemas.microsoft.com/mapi/proptag/0x10130102) using AppointmentItem.PropertyAccessor.SetProperty, but Outlook won't see your change until you completely dereference and reopen the item.
We need to convert the HTML content to the byte array and then display it in the HTML body then we can able to get the full html body . Until unless byte conversion we are not able to get the html content in the appointment plug-in . please vote if it solve your problem. Thank you :)

Is it possible to directly open the Outlook meeting window?

I am trying to have my application to open the Outlook meeting window with some pre-populated fields.
I have found that this question was already asked here.
However, the code provided in the answer(which works fine) doesn't open the meeting window but the appointement window. Those are two different things that are handled differently in Outlook and what I need is indeed the meeting window.
Is there any way to achieve this or do I absolutely have to open the appointement window first and then invite people to turn it into a meeting?
Create an appointment just as in the other question, but then set the MeetingStatus property of the appointment.
Microsoft.Office.Interop.Outlook.Application outlookApplication = new Microsoft.Office.Interop.Outlook.Application(); ;
Microsoft.Office.Interop.Outlook.AppointmentItem appointmentItem = (Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
// This line was added
appointmentItem.MeetingStatus = Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
appointmentItem.Subject = "Meeting Subject";
appointmentItem.Body = "The body of the meeting";
appointmentItem.Location = "Room #1";
appointmentItem.Start = DateTime.Now;
appointmentItem.Recipients.Add("test#test.com");
appointmentItem.End = DateTime.Now.AddHours(1);
appointmentItem.ReminderSet = true;
appointmentItem.ReminderMinutesBeforeStart = 15;
appointmentItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
appointmentItem.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
appointmentItem.Recipients.ResolveAll();
appointmentItem.Display(true);
One more note to NineBerries good solution, because I had an issue here:
The line
appointmentItem.Recipients.ResolveAll();
is necessary if you have optional attendees in the meeting.
Otherwise they will be reset to "required" even if you set
recipient.Type = Microsoft.Office.Interop.Outlook.OlMeetingRecipientType.olOptional;
before, which is due to "late auto-resolving" of names in Outlook (or so it seems).

Open Contact Card Viewer/Editor from Outlook button

I created a custom ribbon for Microsoft Outlook and I have a button called view profile. I want to be able to bring up the Contact Card Viewer/Editor for the current user. I created a call back and I think I have the general idea of how to get his done but I am having trouble making the connection once I find the current user to getting it to open for that user. Here is the code I have so far for the call back.
public void button2_Click(Office.IRibbonControl control)
{
var appOutlook = new Microsoft.Office.Interop.Outlook.Application();
Outlook.ExchangeUser currentUser = appOutlook.Session.CurrentUser.AddressEntry.GetExchangeUser();
ContactItem contactinfo = currentUser;
contactinfo.ShowBusinessCardEditor();
}
You can use the ContactCard.
Here is C# code converted from the VBA example on this page https://msdn.microsoft.com/en-us/library/office/ff869218.aspx
var session = appOutlook.Session;
var adr = session.CurrentUser.AddressEntry;
var cc = session.CreateContactCard(adr);
cc.Show(MsoContactCardStyle.msoContactCardFull, 100, 100, 100, 100, 100, true);
The easiest way is just calling the .Display(modal: true / false) method on the ContactItem.
ContactItem contact = ...
contact.Display(true); // for modal
Simply call AddressEntry.Details:
Outlook.AddressEntry currentUser = appOutlook.Session.CurrentUser.AddressEntry;
currentUser.Details();

Outlook appointment on Server not working

I have created Following function to set Outlook appointment. It's work fine while running in localhost with visual Studio Editor.
But when I upload publish files on server its not working.
Do I need to set anything in server for Outlook or need to include any additional dll/files?
Any help will be appreciated. Pls let me know, if need more information.
public void OutLookReminder(string DateTimeVal)
{
Outlook.Application outlookApp = new Outlook.Application(); // creates new outlook app
Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // creates a new appointment
oAppointment.Subject = "........Subject"; // set the subject
oAppointment.Body = "--------Body"; // set the body
oAppointment.Location = "-------Location"; // set the location
oAppointment.Start = DateTime.ParseExact(DateTimeVal, "dd/MM/yyyy H:mm",null); // Set the start date
oAppointment.End = DateTime.ParseExact(DateTimeVal, "dd/MM/yyyy H:mm", null); // End date
oAppointment.ReminderSet = true; // Set the reminder
oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; // appointment importance
oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;
// save the appointment
oAppointment.Save();
}
Do you mean you are running this under a service (such as IIS)? You cannot do that.
Where is the appointment supposed to be created? Current user who is using your code in a browser (then your code needs to run locally in JavaScript)?

Categories