TPC SharePoint Events

Starting in TPC 5.2, developers can now track and read messages sent between The Portal Connector and SharePoint. All the communication between The Portal Connector and SharePoint is done on the server-side.

Server-side Events

Server-side events happen on the web server and are written in C#. To use them you must have access to the Sitefinity application code, Visual Studio and be knowledgeable in C#. There are currently three events and one interface that the developer can access for information regarding SharePoint Events: TpcSharePointUploadEvent, TpcSharePointEditEvent, TpcSharePointDeleteEvent, and the interface ITpcSharePointEvent.

The TpcSharePointUploadEvent fires immediately after a file has been uploaded to SharePoint using The Portal Connector. This event gives access to the SharePoint Connection Manager, Entity Logical Name, Entity Id, Filename, Sender, and Origin. This event can be used to track files that have been uploaded to SharePoint through The Portal Connector.

The TpcSharePointEditEvent fires immediately after a file has been edited on SharePoint using The Portal Connector. This event gives access to the SharePoint Connection Manager, Entity Logical Name, Entity Id, Filename, Sender, and Origin. This event can be used to track files that have been edited on SharePoint through The Portal Connector.

The TpcSharePointDeleteEvent fires immediately after a file has been deleted on SharePoint using The Portal Connector. This event gives access to the SharePoint Connection Manager, Entity Logical Name, Entity Id, Filename, Sender, and Origin. This event can be used to track files that have been deleted from SharePoint through The Portal Connector.

The ITpcSharePointEvent interface is fired immediately after a file has been uploaded, edited, or deleted on/from SharePoint using The Portal Connector. All of the TPC SharePoint Events inherit this interface, so it is a simple access point to listen for any TPC Event regarding SharePoint. This interface gives access to the SharePoint Connection Manager, Filename, and Sender. This interface can be used to listen to all messages sent to SharePoint from The Portal Connector.
 

Server-side Code

When writing event handlers on the server-side, it is important to subscribe your handlers after Sitefinity has been “Bootstrapped”. Bootstrapped is when the application is setting up anything required for the application to function correctly. In order to be sure that the application in the correct state to subscribe your event handlers, the following code can be added to the Global.asax.cs file within the Sitefinity Application in Visual Studio. This file contains a number of events that fire in response to various conditions in the application. The one we are interested in is Application_Start which fires as the application is starting up. Below it we add a new method (Bootstrapper_Initialized) to check the current start-up status and subscribe to the events when appropriate. Then we attach it to the Sitefinity Bootstrapper.Initialized event. When the application starts, the Application_Start event fires, attaches our method which then sets up our event handlers. While you can put your event handlers virtually anywhere in the application, it is important to subscribe to them as shown below to ensure that the application is in the correct state to allow the handlers to be subscribed to. 
 
Code Example 1: Subscribing to events

protected void Application_Start(object sender, EventArgs e) {   Bootstrapper.Initialized += Bootstrapper_Initialized; } void Bootstrapper_Initialized (object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e) {   if (e.CommandName == "Bootstrapped")   {   //Subscribe to SharePoint Upload Event   EventHub.Subscribe<TpcSharePointUploadEvent>(SharePointUploadEventHandler);     //Subscribe to SharePoint Edit Event   EventHub.Subscribe<TpcSharePointEditEvent>(SharePointEditEventHandler);     //Subscribe to SharePoint Delete Event   EventHub.Subscribe<TpcSharePointDeleteEvent>(SharePointDeleteEventHandler);     //Subscribe to SharePoint Event Interface (All Previous Events)   EventHub.Subscribe<ITpcSharePointEvent>(SharePointEventHandler);   } }

In the above example, the TpcSharePointUploadEvent, TpcSharePointEditEvent, TpcSharePointDeleteEvent, and ITpcSharePointEvent are being subscribed to by passing the name of the function to the Subscribe function. The actual handlers it is referring to are shown below.

Code Example 2: Sample TpcSharePointUploadEvent Handler

private void SharePointUploadEventHandler (TpcSharePointUploadEvent @event) {   //SharePoint Connection Manager   SharePointConnectionManager manager = @event.Connection;     //Entity Logical Name   string entityLogicalName = @event.EntityLogicalName;     //Entity Id   Guid entityId = @event.EntityId;     //Sender   object sender = @event.Sender;     //File Name   string filename = @event.FileName;     //Origin   string origin = @event.Origin;     //Your code goes here… }

Example 2 is one of the functions referenced in Example 1. As noted, it contains the SharePoint Connection Manager, Entity Logical Name, Entity Id, Sender, File Name, and Origin. This event is fired after a file is uploaded to SharePoint through The Portal Connector, and does not provide the ability to modify the file upload. This event is used for the purposes of monitoring and tracking file uploads to SharePoint.

Code Example 3: Sample TpcSharePointEditEvent Handler

private void SharePointEditEventHandler (TpcSharePointEditEvent @event) {   //SharePoint Connection Manager   SharePointConnectionManager manager = @event.Connection;     //Entity Logical Name   string entityLogicalName = @event.EntityLogicalName;     //Entity Id   Guid entityId = @event.EntityId;     //Sender   object sender = @event.Sender;     //File Name   string filename = @event.FileName;     //Origin   string origin = @event.Origin;     //Your code goes here… }

Example 3 is one of the functions referenced in Example 1. As noted, it contains the SharePoint Connection Manager, Entity Logical Name, Entity Id, Sender, File Name, and Origin. This event is fired after a file is edited in SharePoint through The Portal Connector, and does not provide the ability to modify the file. This event is used for the purposes of monitoring and tracking file editing in SharePoint.

Code Example 4: Sample TpcSharePointDeleteEvent Handler

private void SharePointDeleteEventHandler (TpcSharePointDeleteEvent @event) {   //SharePoint Connection Manager   SharePointConnectionManager manager = @event.Connection;     //Entity Logical Name   string entityLogicalName = @event.EntityLogicalName;     //Entity Id   Guid entityId = @event.EntityId;     //Sender   object sender = @event.Sender;     //File Name   string filename = @event.FileName;     //Origin   string origin = @event.Origin;     //Your code goes here… }

Example 4 is one of the functions referenced in Example 1. As noted, it contains the SharePoint Connection Manager, Entity Logical Name, Entity Id, Sender, File Name, and Origin. This event is fired after a file is deleted in SharePoint through The Portal Connector, and does not provide the ability to modify the file. This event is used for the purposes of monitoring and tracking file deletion in SharePoint.

Code Example 5: Sample ITpcSharePointEvent Handler

private void SharePointEventHandler (ITpcSharePointEvent @event) {   //SharePoint Connection Manager   SharePointConnectionManager manager = @event.Connection;     //Sender   object sender = @event.Sender;     //File Name   string filename = @event.FileName;     //Your code goes here… }

Example 5 is one of the functions referenced in Example 1. As noted, it contains the SharePoint Connection Manager, Sender, and File Name. This event is fired after a file is uploaded, edited, or deleted in SharePoint through The Portal Connector, and does not provide the ability to modify the file. This event is used for the purposes of monitoring and tracking all file processes between SharePoint and The Portal Connector.