SharePoint 2013/Online: JavaScript Injection using Embed JavaScript Pattern

Based on the latest recommendations from Microsoft, User Interface SharePoint 2013 & SharePoint Online should be customized using Client Side Frameworks and not using Traditional Master Page Customization based on Branding Solutions.

Moving on the same recommendations we will discuss JavaScript Injection or Embed JavaScript Pattern which is one of the newly recommended techniques from Microsoft that enables the developers to write applications to push the client scripts into the page from outside SharePoint Environment.

This sounds similar to the implementation of the Delegate Controls in an on premise SharePoint Installation but in this case we push the scripts from outside of the SharePoint Environment.

Using Client Side Frameworks such as JQuery along with this technique we can perform DOM Manipulation (adding, removing, modifying HTML Elements) as and when needed in whichever ways.

We must make use of Custom Actions with SharePoint App Model in order to implement Embed JavaScript Pattern by utilizing location identifier ScriptLink that can be accessed through UserCustomActions collection of SPWeb Object.

In this in this article we will see how to implement Embed JavaScript Pattern in real time business applications as below-

Lets’ start with a SharePoint App Project by selecting App for SharePoint Project Template


Specify the Site URL

Choose Provider-Hosted as hosting model in order to develop High Trust Apps


Choose ASP.Net Web Forms Application to create Web Application Project for the Provider Hosted App


Provide Certificate details for the High Trust Apps


Now once the project is ready we can start with the coding part of Solution as follows-

Steps 1 – In the default.aspx add HTML code to provide UI for the solution


In the App.js file add the following code-

Steps 2 – Refer the JQuery File from the CDN

Steps 3 – Calling InjectJavaScript Function


Steps 4 – Inside InjectJavaScript Function, check if MDS is enabled and if it is Register Custom JavaScript code using RegisterModuleInit function.

The first parameter to the RegisterModuleInit function is the path to the JavaScript file relative to the _layouts folder.  Since this solution deploys the JavaScript file into a folder under the _layouts virtual directory, you have provided that relative path.  The second parameter is the entry point function which is LoadJSInsideHostWeb.

This approach will ensure that this JavaScript will work both with MDS enabled & disabled sites.


Steps 5 – Inside LoadJSInsideHostWeb function, we are calling LoadJQuery function to include JQuery file from the CDN and once loaded successfully it is calling ModifyHostWeb which will do the actual job of Injecting JavaScript Code to the Host Web


Steps 6 – Inside ModifyHostWeb function

  • We are manipulating the Site Title of the Host Web by using JQuery Element Identifier
  • We are replacing the Site Icon of the Host Web by using JQuery Element Identifier


Steps 7 – Inside LoadJQuery function we are loading JQuery File from the CDN


Steps 8 – Here we are hooking up the button click event for InjectJs & RemoveJS HTML buttons

Inside each event handler we are calling InjectJavaScript & RemoveJavaScript functions by passing Client Context to the Host Web & Web Object referring the Host Web and setting the notification message on the SharePoint App Page (default.aspx) to show the status of the operation


Steps 9 – Inside InjectJavaScript function we are making use of Custom Actions Framework for SharePoint to inject JavaScript based customization inside the Host Web in the following steps-


Preparing path of the Script file that we are going to inject into the Host Web and embedding it by creating the dynamic script block with src attribute set to the script file path.

Then we are retrieving the UserCustomActions collection in context of the Host Web and adding the new User Custom Action with Location as Script Link and Script Block as dynamic script block created earlier



Steps 10 – Inside RemoveJavaScript Function we are removing the User Custom Action from the UserCustomActions collection in context of the Host Web based on the Description & Location property of the User Custom Action.


With this we are done with the code.

Now lets’ run the App and see it in action by pressing F5 in Visual Studio

Once the App launched we can see the UI with a Result Panel & two HTML Buttons

  • Inject JavaScript to Host Web – This button will Inject JavaScript to the Host Web using User Custom Action
  • Remove JavaScript to Host Web – This button will Remove JavaScript from the Host Web by removing User Custom Action


If we look the Host Web before embedding the script to it, it would look like as follows. Notice we have default Site Icon and Title which was provided at the time of site creation


Now on App Page click on Inject JavaScript to Host Web button to push custom JavaScript into the Host Web

On clicking the button we can see the success message in the Result Panel confirming that the JavaScript has been applied to the Host Web


If we revisit the Host Web we can see the Site Icon and Title has been changed as per the code we had added to the custom JavaScript File that we have injected into Host Web

And since this change takes place at the Master Page Level, we can see the effect of the change all across the site on every screen as shown below:





Now in order to unplug the JavaScript based customizations out of the Host Web we can click on Remove JavaScript to Host Web

Once the Remove operation has been completed successfully we can see the result panel confirming the success of the operation.


And we can go back to Host Web to ensure that the Site Icon and Original Title are restored back as usual.


So we can clearly see the “Embed JavaScript Pattern” is very effective as it gives you handle on customizing Host Web Elements from outside the SharePoint itself.

Point of Caution

It is the responsibility of the App Developer to handler the smooth removal of the injected code as soon as the App gets uninstalled. There are a couple of issues that I would like to point out around this fact as follows:

If code is injected using SharePoint Hosted App, then it is not possible to get it removed the injected code automatically by any mean. In this case it is required to provide a User Interface or any other mean to execute the code for removal of injected Javascript followed by User Training for the Administrators to run the code first before uninstalling the App.

If code is injected using Provider Hosted App, then it is possible to get it removed automatically by handling App Uninstalling Event using Remote Event Receivers. You can refer to following of my earlier blogs on Remote Event Receivers to get better understanding on usage

That’s all for this demo.

Hope you find it helpful.

SharePoint 2013 : How to enable Remote Event Receivers with existing List & Libraries

While working with Remote Event Receivers I came across a scenario where we need to hook up the Event Handlers to any of the existing lists in a site.

For example we got a list called “Products” in which we need to stop the users to delete any list item.

This requirement can be achieved simply by deploying a Farm Solution containing the Event Receiver SPI hooked up with the Products List Item Deleting Event.

But what if we are not allowed to deploy any code solution in SharePoint Environment?

The simple answer to this complex question is involve Remote Event Receivers and hooked them up to the existing list which is a bit of tricky task.

In this article we will see to the steps to register Remote Event Receivers with the existing Lists & Libraries while utilizing our knowledge based on earlier articles in this series which can be reached at:

  1. SharePoint 2013: Remote Event Receivers
  2. SharePoint 2013: How to develop Remote Event Receivers for App Events
  3. SharePoint 2013: How to develop Remote Event Receivers for List And List Item Events
  4. SharePoint 2013 : Remote Event Receivers on List Item Event – Real Business Scenarios

Let start with a Provider Hosted App that will register the Remote Event Receivers with the existing SharePoint Lists

Create “New Project”


Select “App for SharePoint” as SharePoint Project Template



Specify the URL of the Debugging Site, which is called as Host Web in case of an App

Select “Provider-Hosted” as App Hosting Model


Select “ASP.Net Web Forms Application” as Project Template for the Remote Web


Enter Certificate Details as we did in earlier demos



On successful creation of the Solution two projects should be added as shown below.

“PH-Bind-Event-Receivers-With-Existing-List” – Represents the Code Base for the Provider Hosted App

“PH-Bind-Event-Receivers-With-Existing-ListWeb” – Represents the Code Base for the Remote Web


Select App Project and Press F4 to see the properties

Under “App for SharePoint Events” Set the Events that the App is required to respond to.

Here we would need only “App Installed” and “App Uninstalling” Event to work on so we would enable only these two events by changing the value to “True”


As soon as we enable the App Events a new service class gets added to the Solution by the name “AppEventReceiver.svc” under the Services Folder


Detailed walkthrough of the highlighted steps is as follows-

Step 1- Check for the Event Raised and make sure that we are handling only “AppInstalled” Event

Step 2- This step is tricky of all. It is important to notice how we are getting the full path of the Service Class that will be listening to the lists events.

Since this is the Service that will be hosted somewhere outside SharePoint due to this usual SharePoint Tokens will not work here which means “~remoteAppUrl” Url Token will not work in this case.

So in order to get the complete path to the Service Class we need to make use of “OperationContext” class.

The “OperationContext” class provides you methods (as highlighted below) to extract Absolute Uri to the Service Class irrespective of where it is hosted.

Step 3- Retrieve the Remote Web URL to get the fully qualified path of Service Class

Step 4- Instantiate the App Context by calling “CreateAppEventClientContext” method shipped with TokenHelper.cs Class to facilitates App Authentication Tokens

Step 5- Load the Products List using traditional CSOM way

Step 6- Instantiate new Event Receiver Object using “EventReceiverDefinitionCreationInformation” class. It is important to set following properties to get this Event Receiver added to the collection of Event Receivers of Product List.

Important Properties to set are-

EventType                          –             Specifies the type of Event that can trigger receiver like here we are assigning it to “Item Deleting” Even

ReceiverName                  –             Specifies the unique name of this Event Receiver that can be used to identify it in Event Receivers Collection of Products List

ReceiverUrl                        –             Specifies the full path to Receiver. Assign the value of the Full Path that we have retrieved in Step 2

SequenceNumber           –             Specifies the Sequence Number for the Event Receiver to add to the Event Receivers Collection of the Product List

Step 7 – Add the Event Receiver Object to Products List Event Receivers Collection


Step 8 – The other Event that we consider is “AppUninstalling”. Since this Event is quite useful to perform cleanup activities like removing the Event Receiver registration with the respective as soon as the App gets uninstalled.

Step 9 – Same as Step 4 above

Step 10 – Same as Step 5 above

Step 11- Loop through all the Event Receivers registered with Products List and find a specific Event Receiver by Name value (recall Step – 6 where we have specified value to “ReceiverName” Property of Event Receiver)

Step 12- Once we identified the specific Event Receiver we can remove it from Event Receivers Collection of Products List


Step 13- This involves Handling of ItemDeleting Event of Products List. We can check the incoming Event Type by using “EventType” property of Event Object (properties)

Step 14- Validates the name of the list that generates the Event, this step is necessary to ensure that we are responding to right Event generated from an intended list

Step 15- Set “ErrorMessage” that needs to be displayed to the User in case User actions try to delete List Items

Step 16- Set “Status” to “CancelWithError” since we want to cancel the User action along with showing him proper error message


That’s it. We are all set to see the efforts in action.

Build and Deploy Solution to SharePoint

Trust the App when asked to and move on



Once deployed successfully we can test the Remote Event Receiver as follows-

Navigate to the Products List

Try to Delete any Item in the list and see if you are able to see the Error Message you set with in Event Receiver’s Properties



Sure enough you will get the Error Message displayed on to Error Page to which SharePoint Navigates you to.


This implementation is really amazing and I can see lot of potential in terms of handling discrete Business Rule and Validation on the existing SharePoint Lists and Libraries without deploying and Server Code in SharePoint Domain.

Hope you find it helpful.

SharePoint 2013 : Remote Event Receivers on List Item Event – Real Business Scenarios

In this fourth article in the series on Remote Event Receivers, we will look into some of the applicable business cases around the Remote Event Handlers.

You can reach the previous three articles in this series as follows:

  1. SharePoint 2013: Remote Event Receivers
  2. SharePoint 2013: How to develop Remote Event Receivers for App Events
  3. SharePoint 2013: How to develop Remote Event Receivers for List And List Item Events

We will investigate the working of the following scenarios which are quite obvious while working with SharePoint List & List Items.

Scenario 1 – How to restrict users to delete a certain item

In order to show case this scenario let’s consider an Item “Product-001-1” added to the List called “Products” as shown below:

Now let’s try to delete this item as highlighted below-



As soon as user try to delete the item SharePoint looks for any registered Event Receiver with the List and looking for its Receiver Definition to see what all event this Receiver is allowed to receive and executes it.

In our case we have registered the following Receiver Definition with the list-


Let’s investigate the code for register Remote Event Handler –

Since this a Before Event (as explained in one of the earlier post “SharePoint 2013: Remote Event Receivers”), we need to write the Code in “ProcessEvent” Method.

Step 1 is to check the type of Event that triggers this Event Receiver by making use of “SPRemoteEventType” Enum and “EventType” Property of the “SPRemoteEventProperties” object

Step 2 is to check the List Title by making use of “ItemEventProperties” collection of “SPRemoteEventProperties” object and ensure that we are handling Delete Events received only from a specific which in our case is “Products”

Step 3 is to check for the desired condition and if satisfied then set “ErrorMessage” and “Status” properties exposed by “SPRemoteEventResult” object.

In this case we have set a user friendly message and set status to “CancelWithError”. For all the valid status values we can look for “SPRemoteEventServiceStatus” Enum.

Step 4 is to return the SPRemoteEventResult object back to SharePoint


The setting we did in Step 3 will let SharePoint to terminate the event raised due user action and return the error message to SharePoint which would be rendered as Error Message for the user as highlighted below-


Scenario 2 – How to get Item Details after Item has been updated

In order to show case this scenario we can consider the same item as above and this time let’s let Edit the item as highlighted below



Now next thing is to investigate the code for registered Remote Event Handler –

Since this an After Event (as explained in one of the earlier post “SharePoint 2013: Remote Event Receivers”), we need to write the Code in “ProcessOneWayEvent” Method.

Step 1 & Step 2 are same as mentioned above

Step 3 is to fetch the Items Properties by making use of “ItemEventProperties” collection and preparing a variable to make it use later

It is worth noting that at this point, “ItemEventProperties” collection will contain the Properties of the List Item after the Update got succeed, which means that we can find all the updated values in the respective columns for the list item as highlighted and can consume as needed

Just to keep the story simple we are consuming these values in compiling a message to be written to Windows Event Log.

It is important to notice how we are accessing values of “Title” & “Price” Columns of that Item.

Step 4 is to write this message variable to Windows Event Log


Once execution is successful we can see the message logged in the Windows Event Log as shown below


Scenario 3 – How to validate User inputs using Remote Event Receivers

This scenario will talk on validating user inputs and terminate the execution as soon as the input value falls outside the valid value range.

For instance in this demo we are assuming a hypothetical business requirement demanding “Item Price should not exceed $300”

In order to showcase this validation scenario we can consider the same Item as mentioned above.

Let’s edit the item as shown below


Now specify the Item Price any greater than $300, here we are updating the Product Price as $350

As soon as we try to save the item, SharePoint handover the control to Remote Event Receiver which is registered with this list on Item Updating Event and Event Receiver validate the Item Price value against the specified business logic which on fail produces the error message “Price cannot exceed $300” as highlighted below-


If we look into the logic driving this business requirement we can see

Step 1 is to write the code in “ProcessEvent” handler as this action of updating the List Item is a Before Event [ItemUpdating]

Step 2 is to identify the Event Type and ensure that the business logic should be executed only in case of ItemUpdating event

Step 3 is to identify the Source of Event and ensure to handle the event only if the Source is “Product” List

Step 4 is to read the value of “Price” Field entered by the user

Step 5 is to validate the input Price value against the needed business logic

Step 6 is to set the “ErrorMessage” and “Status” Properties of the SPRemoteEventResult object. Set “Price cannot exceed $300” as Error Message and “CancelWithError” as Status. These properties let SharePoint to terminate the Event generated and no updates to the Item will get persisted.

Finally Step 7 is to capture information about the Item and Event and write it back to Windows Event Log.


These few simple scenarios might help you to understand the mechanics and objects exposed by Remote Event Receiver API that can be extended to achieve even more complex business scenarios at hand.

Hope you find it helpful… 🙂

SharePoint 2013: How to develop Remote Event Receivers for List And List Item Events

In this third post on Remote Event Receivers we are going to explore the mechanics revolving around Remote Event Receivers on List/List Item Events.

The previous two posts in this series can be reached out at:

  1. SharePoint 2013: Remote Event Receivers
  2. SharePoint 2013: How to develop Remote Event Receivers for App Events

In order to show case this scenario we need to start with a Provider Hosted App as highlighted in the following steps:

  • Select “App for SharePoint” Project Template


  • Specify the URL of Host Web and select “Provider-Hosted” as Hosting Model.


  • Select “ASP.Net Web Forms Application” as Project Template for Hosting the Remote Web


  • Specify the Security Certificate details based on SharePoint Provider Hosted App Development Environment configuration


Click Finish to complete the Visual Studio Solution Wizard.

Now next thing is to add the required items to the SharePoint App Project

  • Select App Project => New Item => Add


  • Select “List” as Project Item Template and the list as “Products”

This List will act as the Source of Events which will be delegated to the Remote Event Receiver


On List Settings Page –

  • Select a Display Name for the List
  • Choose Template for List Instance as “Custom List”


In List Designer –

  • On Columns Tab, specify the Columns/Fields you need to add to the list

I took ProductName & Price as two fields to be added for Products List


  • On the List Tab, verify the Site Relative Url of List


Once we got our list created and configured, it is time to add a new SharePoint Item to the project. Guess What??

The Remote Event Receiver. Yes!!!!

  • Select App Project => New Item => Add


  • Select “Remote Event Receiver” as Project Item Template


  • Select Type of Event Receiver as “List Item Events”


  • Select Event Source as “Products” List
  • Choose what all events you want to let handle by this Remote Event Receiver. For now I am choosing “Item Added”, “Item Updated” and “Item Deleted” events


As soon as the List is added to the Project a Feature scoped to the App Web gets also added

Once we are done with the configuration steps as shown above, we can see following artifacts added to the Project as highlighted below:

  • Products List
  • List Instance of the Products List
  • Remote Event Receiver


If we notice Remote Web Project which is nothing but an ASP.Net Application, we can see the following artifacts added already to it:

  • Service Class [Product-Remote-Event-Receiver]: That represent the Remote Event Handler Code Base
  • TokenHelper.cs & SharePointContext.cs : These helper classes are added to VS2013 to execute all the heavy lifting related to Authorization and Authentication algorithms easily between Remote Web Server(SPWeb Host) & SharePoint Server(Front-end Server).


We will revisit the Service Class Code in a short while to understand its internal plumbing.

But for now let’s build the Solution and Run it.


Trust the App with all needed permissions when prompted.


As soon as we Grant the App with all of the required permissions, the App Launcher redirects the User to the Start Page for the App, which is residing in the Remote Web for this case as highlighted below


We can see the App Launcher added to the Site Contents of the Host Web as shown below


We can ensure the presence of App Web by using SharePoint Manager and inspects Products List that has been provisioned to the App Web during the App Deployment


We can browse the App Web from Browser also as shown below


Now in order to test the Event Receiver, let’s create a test item in Products List as shown below


Specify Product Name & Price and Click Save button


As soon as Item gets added, it triggers “ItemAdded” event which is delegated to Remote Event Receiver by SharePoint.

In Remote Event Receiver we have two methods “ProcessEvent” & “ProcessOneWayEvent”.

For more details on these methods you can revisit my earlier post SharePoint 2013: Remote Event Receivers

On Item added we can see Breakpoint hit in “ProcessEvent” Method as shown below


Similarly we can see Break Point hit every time the Item gets updated as highlighted in below steps




Likewise we can see Break Point hit when Item gets deleted as highlighted in below steps



Since we registered the Event Receivers to handle “ItemAdded”, “ItemUpdated”, “ItemDeleted” only so none of the other Events would be delegated to Remote Event Receiver by SharePoint.

In case if any more Events need to be handled we need to add <Receiver> Elements in the Element.xml file associated with Remote Event Receiver as and when needed.

SPRemoteEventProperties Object is your real friend:

“ProcessEvent” method of Remote Event Receiver provides an object called as “properties” that exposes a lot of useful properties that can help us to perform any desired operation on the Web or List or List Item.

Following are the important properties that are exposed by “properties” object:

  • Event Type: Returns the type of Event Triggered by SharePoint Source Object
  • Item Event Properties: If the Event Type is of “List Item Type”, then “ItemEventProperties” collection is returned with data entered by user in each field of the List Item
  • List Properties: Returns the List specific properties like List Name, List ID and so on
  • Login User Properties: Return User specific properties like User ID, Login Name and so on
  • Source Web Properties: Return Web specific properties like Web Url


This post is more focused on the mechanics offered by SharePoint around Remote Event Receivers for List/List Item Events.

We will meet in another post where it will be more focused on to the implementation details on Event Receivers dancing around some valid Business Use Cases.

Hope you find this post helpful.

SharePoint 2013: How to develop Remote Event Receivers for App Events

In this second post on Remote Event Receivers we are going to explore the implementation details of “Remote Event Handlers for App Events”.

In case you need to recall the concepts related to “Remote Event Receivers”, you can refer to my First post in this series SharePoint 2013: Remote Event Receivers

In order to show case the implementation details of Remote Event Handler for App Events, let’s start with creating a Provider Hosted App by using following steps:

Create New Project in Visual Studio using “App for SharePoint” Project template


Specify Host Web URL and choose “Provider-hosted” as App Type


Choose “ASP.Net Web Forms Application” as Project Template to create Remote Web for our Provider Hosted App


Specify Certification Details based on the configuration of Provider-Hosted App Development Environment. Following details needs to be provided:

  • Certificate Location
  • Password
  • Issuer ID


Once all the above steps executed successfully we will get a new Solution created with two projects:

  • PH-AppEventLifeCycle which is a Provider Hosted App
  • PH-AppEventLifeCycleWeb which is a Remote Web for App


Select Provider Hosted App Project and press F4 to see the Project Properties. In the Project Properties look for “App for SharePoint Events” section and enable all events that you want to get handled by Remote Event Receiver.

Here I have set all the three events “Handle App Installed”, “Handle App Uninstalling, “Handle App Upgraded” to True, this setting will allow SharePoint to delegate respective events to the registered Event Receiver.


In case you need to create an App Web for your Provider Hosted Web (though it is not necessary) you must have atleast one Web Scoped Artifact added in the Project as this action will force SharePoint App Framework to provision App Web during the App Deployment.

In this case I have added a Dummy Module deploying some sample file just to force SharePoint to create an App Web for our Provider Hosted App.


It is noteworthy to look for AppManifest.xml file as most of the configuration settings for an App are derived from here only.

In General Tab, we have two noteworthy Properties:

  • Start Page: It allows you to set any Page as App Start Page. In this case we have set it point to the Default.aspx Page in Remote Web.
  • Query String : Allows adding additional information as Query String Parameters while redirecting to the Start Page


In Permission Tab, we can specify the set of Permissions that App will need to perform desired tasks.

At the time of App Installation, App will request this permission set to be granted and that we will see few steps down the line.


Now the very next thing is to investigate the constitution of Remote Web Project “PH-AppEventLifeCycleWeb


In this Project we have following important Files to look for:

  • Default.aspx: This is the start page for Provided Hosted App as we set it in earlier steps. In this page we can perform actions that are desired for a specific task. For example we can provide UI for end users to interact with the App.

In this demo the code sample is reading the title of the Hosting Web as follows:

           Steps 1: Getting URL of the Host Web by reading “SPHostUrl” Parameter

           Steps 2: Instantiating Client Context by Calling GetS2SClientContextWithWindowsIdentity method provided by SharePoint Infrastructure by means of TokenHelper.cs Class

           Step 3: Once Client Context is Instantiated, we can make use of Managed CSOM to load the Web and read its Title Property as shown below


  • Scripts: We can go with the default set of scripts added during creation of the project, else we can add any desired script file to it


  • AppEventReceiver.svc : This Service class has been added to the Project as soon as you add a “Remote Event Receiver” Project Item to the Project


Let’s walkthrough through the code file and see what we got.

Step 1: Add “Microsoft.SharePoint.Client.EventReceivers” Namespace which is needed for Remote Service to handle Remote Events and inherit the class from “IRemoteEventService”

Step 2: Override the method ProcessEvent

Step 3: Specify Remote Event Service Status if you want to continue or reject, so that execution succeed or revert back

Step 4: Perform actions as per the business requirement. Here I am adding logs to Windows Event Log

Step 5: Return the Event Result back to SharePoint


Step 1: Override the method ProcessOneWayEvent

Step 2: Perform actions as per the business requirement. Here I am adding logs to Windows Event Log


  • Web.config: In Web.config file, there are a couple of “AppSettings” that are important to take note of-

              ClientId: Generated Automatically by Visual Studio for development perspective. At the time of App registration this can be regenerated and used accordingly.

              ClientSigningCertificatePath: Specify the path of Client Certificate exported during environment configuration.

              ClientSigningCertificatePassword: Specify the path of Client Certificate Password specified to protect the Certificate during environment configuration.

               IssuerId: Specify the path of Issuer ID generated during environment configuration


With this we are done with inspection to all of the important files in our solution.

Now it is time to Build the Solution and Run it.

In the below screen shot we can see the Client ID is generated by Visual Studio Tools during Build Process.


Once the Solution Build & Run successfully, the App Framework looks for the AppManifest.xml and find a permission set to be granted by App User on the Host Web.

So we have to grant permissions as specified in Permissions Tab of AppManifest.xml file and in order to grant the permissions click “Trust It”.


As soon as we grant the permissions, App Launcher looks for the App Start Page as specified in General Tab of AppManifest.xml file and Redirect the user to that page.

If we notice the URL in below screen shot, we find the App Start Page is default.aspx of Remote Web as specified in AppManifest.xml file for the App.


If we investigate the Site Structure using any tool like SharePoint Manager (one of my favorites), we can see an App Web by the name “PH-AppEventLifeCycle” is also provisioned due to the presence of Dummy Module we added to the Project earlier.


After App is getting installed successfully, we can also see an event log is added to the Windows Application Log as shown below based on the message we placed in the “AppEventReceiver.svc” code file:


Likewise while the App is uninstalling, we can see an event log is added to the Windows Application Log as shown below based on the message we placed in the “AppEventReceiver.svc” code file:


This simple walkthrough can help you to understand on how to deal with the App Events.

We can utilize these semantics under different business cases liking registering Event Receivers for existing lists or notifying users and so on.

Hope you find it helpful.

See you all in the next post of this series. 🙂

SharePoint 2013: Remote Event Receivers

In this first article on “Remote Event Receivers”, we will understand the concept of “Remote Events” & “Remote Event Handlers” which is a newly introduced concept in SharePoint 2013.

What are Remote Events & Remote Event Receivers?

Remote Events are meant to be considered in context of SharePoint Apps only, since the newly introduced SharePoint Apps Model has got restrictions on how the code should be executed in SharePoint Environment.

SharePoint Apps Model restricts the Apps to execute any server side code within SharePoint execution boundaries. But there are scenarios where it becomes really necessary to handle certain Events during the App Life Cycle.

For instance this is an obvious scenario to perform any desired operation like “creating a Global Settings List in Host Web” during App Installation, similarly it is also a valid scenarios where an Email notification needs to send to the App Users with some of the relevant information regarding the app or taking backup of the App Data or Settings on to the Host Web before actually removing the App during App Uninstallation.

Due to such valid business cases, it is necessary to have a mechanism to handle such events from within the Apps and that’s where Remote Event Handler comes into play.

There are broadly two types of Remote Events most likely to be triggered out of an App:

  1. App Events
    • Handle App Installed
    • Handle App Uninstalling
    • Handle App Upgraded


  1. List Events : All list events are supported which are kept within SPRemoteEventType enumeration
    • ItemAdding
    • ItemUpdating
    • ItemDeleting
    • ItemCheckingIn
    • ItemCheckingOut
    • ItemUncheckingOut
    • ItemAttachmentAdding


The listed events are just a few out of the complete list of Events that are exposed as Remote Events.

For the complete list of Remote Events you can visit SPRemoteEventType Enumeration.

In order to handle all of the above listed Events SharePoint provides following two Handler functions via an Interface “IRemoteEventService”:


  1. ProcessEvent: This is “Before or Synchronous” Handler, which executes before any action (like List Item Added/Updated/Deleted) takes place. This is a Two-Way Event Receivers which means it takes instructions from SharePoint based on User Actions (List Items Added/Deleted), Process it and returns back the result to SharePoint. This function has a return type of type “SPRemoteEventResult”.


  1. ProcessOneWayEvent: This is “After or Asynchronous” Handler, which executes after any action (like List Item Added/Updated/Deleted) completed. This is not a Two-Way Handler so it will just accept the instructions from SharePoint based on User Actions (List Items Added/Deleted) and does not returns back any result or notification to SharePoint. This function should be mainly employed for operations like Logging, Sending Notifications to App Users and so on.


How do Remote Event Receiver Works:

Step1: User Performs Operations that generates an event in SharePoint [Be it App or List Events]

Step2: SharePoint then look for registered Web Service Endpoint designated to handle this event remotely

Step3: Web Service Endpoint process the instructions based on the Event generated from within SharePoint and returns the result back to SharePoint.

In order to perform any action directly from within the Web Service, Web Service Endpoint needs to call Access Control Service to obtain its own signed token.


SharePoint provides the TokenHelper.cs Class file which can be used to make request for necessary tokens.


That is all for this post on Remote Even Receivers.

Hope you will find it helpful.

In the upcoming articles on Remote Event Receivers we will explore the implementation details and see each of the types of Events Receivers in action.

So sit tight and stay tuned. 🙂