Hi,
I am trying to find out if I can prevent users from changing appointments that get created in Outlook from our CRM system.
What I was looking to do is to write a plug-in using VSTO that would be installed onto our users PC's. The plug-in would fire an event when an appointment gets changed that would read details from the appointment item, and if it was one created from our CRM system, would revert the changes made and inform the user. I would also do the same for any appointments that were being deleted by the users as well.
Is any of this possible using VSTO? I have managed to write a plug-in that detects when an item is changed, however I don't how to revert changes back, or read the item details for processing.
Anyone got any ideas on what to do next, or am I being too ambitious with my idea?!
I am trying to find out if I can prevent users from changing appointments that get created in Outlook from our CRM system.
What I was looking to do is to write a plug-in using VSTO that would be installed onto our users PC's. The plug-in would fire an event when an appointment gets changed that would read details from the appointment item, and if it was one created from our CRM system, would revert the changes made and inform the user. I would also do the same for any appointments that were being deleted by the users as well.
Is any of this possible using VSTO? I have managed to write a plug-in that detects when an item is changed, however I don't how to revert changes back, or read the item details for processing.
Anyone got any ideas on what to do next, or am I being too ambitious with my idea?!
Code:
using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace Outlooktest
{
public partial class ThisApplication
{
private MyEventTracker _eventTracker;
private void ThisApplication_Startup(object sender, System.EventArgs e)
{
// Initialise the event tracker
_eventTracker = new MyEventTracker(this);
}
private void ThisApplication_Shutdown(object sender, System.EventArgs e)
{
_eventTracker = null;
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisApplication_Startup);
this.Shutdown += new System.EventHandler(ThisApplication_Shutdown);
}
#endregion
}
public partial class MyEventTracker
{
private Outlook.Items _calendarItems;
internal MyEventTracker(ThisApplication app)
{
// Obtain references to folder objects we need
Outlook.NameSpace NS = app.Application.GetNamespace("MAPI");
Outlook.MAPIFolder calendar = NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
// Store references to the item collections
_calendarItems = calendar.Items;
// Hook into the Change and Remove events for calendar items
_calendarItems.ItemChange += new Outlook.ItemsEvents_ItemChangeEventHandler(CalendarFolderItemChanged);
_calendarItems.ItemRemove += new Outlook.ItemsEvents_ItemRemoveEventHandler(CalendarFolderItemRemoved);
}
private void CalendarFolderItemChanged(object changedItem)
{
MessageBox.Show("An appointment has been changed!");
Outlook.AppointmentItem AI = (Outlook.AppointmentItem)changedItem;
// Need logic to prevent changes being made
}
private void CalendarFolderItemRemoved()
{
MessageBox.Show("An appointment has been removed!");
// Need logic to prevent the item from being removed
}
}
}