none
Appointment Item RRS feed

  • Question

  • Is there a way to either force an Appointment Item to be Read Only?

    If not then is there a way to prevent the user from opening the Appointment Item?

    I am creating Appointment Items via C# code and I wish to prevent the user from altering it, however I do not see anywhere in the API on how to do this.

    I have tried to use appointmentItem.Close(Outlook.OlInspectorClose.olDiscard); however it does not do anything.

    (I have tried other variations as well with no luck)

    (I am working with Outlook 2010 and VS.net 2010)

    Please Advise?

    Wednesday, August 21, 2013 8:52 PM

Answers

  • I figured it out, I needed to add the right event listener code:

    Outlook.ItemEvents_Event _itemEventsY = null;
                                        _itemEventsY = (Outlook.ItemEvents_Event)appointmentItem;
                                        _itemEventsY.Open += new Outlook.ItemEvents_OpenEventHandler(OnItem_OpenY);
                                        _itemEventsY = null;

    private static void OnItem_OpenY(ref bool Cancel)
            {
                Cancel = true;
            }

    • Marked as answer by niyack Friday, August 23, 2013 12:06 PM
    Friday, August 23, 2013 12:06 PM

All replies

  • Hi niyack.

    According to your description, you want to know how to prevent the user from altering any appointments.

    Firstly, I have not found any way to force an Appointment Item to be Read Only.

    For more information, you can see AppointmentItem Object (Outlook)

    Secondly,

    Do you develop with Visual Studio add-in?

    do you want to prevent the user from altering any appointments on the reminder window?

    If yes, please try to add AppointmentItem. Open event and set Cancel=true, so that the user can not open the appointment, see the following code:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                createAppointment();
            }
    
    private void createAppointment()
            {
                Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem);
     
                oAppointment.Subject = "This is the subject for my appointment"; 
                oAppointment.Body = "This is the body text for my appointment"; 
                oAppointment.Location = "Appointment location"; 
     
                // Set the start date
                oAppointment.Start = Convert.ToDateTime ("8/22/2013 10:00:00 AM");
    
                // End date 
                oAppointment.End = Convert.ToDateTime ("8/22/2013 2:00:00 PM");
                // Set the reminder 15 minutes before start
                oAppointment.ReminderSet = true; 
                oAppointment.ReminderMinutesBeforeStart = 20;
     
                oAppointment.Importance = Outlook.OlImportance.olImportanceNormal;
    
                /* OlBusyStatus is enum with following values:
                olBusy
                olFree
                olOutOfOffice
                olTentative
                */
                oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;
     
                // Save the appointment
                oAppointment.Save();
    
                //oAppointment.BeforeAttachmentSave += oAppointment_BeforeAttachmentSave;
                oAppointment.Open += oAppointment_Open;
                // When you call the Save () method, the appointment is saved in Outlook. Another useful method is ForwardAsVcal () which can be used to send the Vcs file via email. 
    
                Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();
                mailItem.To = "xxx@microsoft.com;"; 
                mailItem.Send();
            }
    
            private void oAppointment_Open(ref bool Cancel)
            {
                Cancel = true;
                MessageBox.Show("Sorry, you can not open this appointment");
                //throw new NotImplementedException();
            }
    

    The above code will create a new appointment while opening Outlook.

    If someone received this appointment and try to open and change, the appointment window will not be opened and a hint window will be display.

    See the follow Figure:

    Hope give you help.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, August 22, 2013 10:52 AM
    Moderator
  • Sorry but this does not help, we are trying to open an existing appointment items from the calendar view, just as you would any other appointment item

    I have tried these but all ended in failure:

    Outlook._AppointmentItem appointmentItem = Inspector.CurrentItem as Outlook._AppointmentItem;
    if (appointmentItem != null)
       {
         appointmentItem.Display(false);
         Inspector.Close(Outlook.OlInspectorClose.olDiscard);
         appointmentItem.GetInspector.Close(Outlook.OlInspectorClose.olDiscard);
         appointmentItem.Close(Outlook.OlInspectorClose.olDiscard);
         ((Inspector)appointmentItem).Close(OlInspectorClose.olDiscard);
       }


    • Edited by niyack Thursday, August 22, 2013 1:45 PM
    Thursday, August 22, 2013 1:45 PM
  • I figured it out, I needed to add the right event listener code:

    Outlook.ItemEvents_Event _itemEventsY = null;
                                        _itemEventsY = (Outlook.ItemEvents_Event)appointmentItem;
                                        _itemEventsY.Open += new Outlook.ItemEvents_OpenEventHandler(OnItem_OpenY);
                                        _itemEventsY = null;

    private static void OnItem_OpenY(ref bool Cancel)
            {
                Cancel = true;
            }

    • Marked as answer by niyack Friday, August 23, 2013 12:06 PM
    Friday, August 23, 2013 12:06 PM