Remove duplicate event receivers from site. SharePoint 2013

Use this if you want to remove all duplicate Event Receivers from all lists in a URL.

Add-PSSnapin Microsoft.SharePoint.Powershell
$spWeb = Get-SPWeb http://site
$SPListCollection = $spWeb.Lists;
foreach ($list in $SPListCollection)
$spList = $spWeb.Lists[$list.Title]
$eventReceivers = $spList.EventReceivers
if ($eventReceivers.Count -gt 1)
foreach ($er in $eventReceivers)
for ($i=0; $i -lt $eventReceivers.count; $i++)
if ($er.Assembly -eq $eventReceivers[$i].Assembly -and $er.Type -eq $eventReceivers[$i].Type -and $er.Name -eq $eventReceivers[$i].Name -and $er.Id -ne $eventReceivers[$i].Id)
#add delete code here
$eventReceivers[$i] | Select Name, Assembly, Type, id

SharePoint 2013 – Unable to use JavaScript on page – Scripts do not show up in developer tools

I have been troubleshooting an issue that when you put a script on the page with a content editor or script web part, it does not execute and does not show up in the development tools in Chrome or IE. It was a mystery.

I ran across a blog that was talking about my issue. The problem is the page is redirecting to http://server/_layouts/15/start.aspx#/site/list. This is a minimal download page. If I went to http://server/site/list, the script works fine.

All you have to do is deactivate the site feature called “Minimal Download Strategy”.


If you come across an article outlining how to use Content Editor and Script Web Parts with MDS enabled, please comment. 🙂

Select some text with no ID or Distinct Element

This finds some parent id up the DOM tree, then using contents and filter it finds text nodes (nodeType===3). Then for each text node you can replace the text with other text, or you could use jquery .wrap to wrap it in an element, ie. .wrap(“<div></div>”).

Another senario is when you want to select/change/modify some text but do not want to affect a child node.

    $("#group0 a").contents().filter(function(){
        return this.nodeType === 3
        this.textContent = this.textContent.replace('Text To Select', ''); 
           //(**I had to use nodeValue instead of textContent for IE8 compatibility)

HTML for above example:

<tr id="group0">
    <td colspan="100" nowrap="" class="ms-gb">
        <a href="javascript:" onclick="javascript:ExpCollGroup('1404-1_', 'img_1404-1_',event, false);return false;">
			<img src="/_layouts/images/plus.gif" border="0" alt="expand" id="img_1404-1_">
		Text to select
		</a> : General&nbsp;<span style="font-weight: lighter;display: inline-block;">(5)</span>

Get ID of custom site template SharePoint 2013

Open SharePoint 2013 Management Shell as Administrator

Enter this:

$site = Get-SPSite > Press Enter

$loc = [System.Int64]::Parse(1033) >Press Enter

$site.GetWebTemplates($loc) | Select-Object -ExpandProperty Name > Press Enter

Your newly saved template should be at the bottom of the list. This ID can be used in custom code to create a new site programmatically.

Here is a JavaScript example…

var siteUrl = '/';

function createWebSite() {
    //alert("Project name: " + form1.projectname.value + " Project Description: " + form1.projectdescription.value);
    $('.project-form').append("<img id='spinner' src=''/>")
    var projectDescription = form1.projectdescription.value;
    var projectLanguage = 1033;
    var projectTitle = form1.projectname.value;
    var projectUrl = form1.projectname.value;
    var projectPermissions = false;
    var webTemplate = '{DF4D4512-8BE6-43BF-B7FB-99BE4763923C}';

    var clientContext = new SP.ClientContext(siteUrl);
    this.oWebsite = clientContext.get_web();

    var webCreateInfo = new SP.WebCreationInformation();

    this.oNewWebsite = this.oWebsite.get_webs().add(webCreateInfo);

    clientContext.load(this.oNewWebsite, 'ServerRelativeUrl', 'Created');

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));


function onQuerySucceeded(sender, args) {
    $(".project-form").append("Your site has been created");

    //alert('Title: ' + this.oWebsite.get_title() + ' Description: ' + this.oWebsite.get_description());

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

Read JSON data with # (pound sign) and @ (at sign)


    "locenter": [
            "loname": {
                "@empid": "1001",
                "#text": "FE1"
            "centers": [
                    "@id": "0000100001",
                    "#text": "dcgiDal"
            "loname": {
                "@empid": "1002",
                "#text": "FE2"
            "centers": [
                    "@id": "0000300006",
                    "#text": "dcgiDah"
                    "@id": "0000100006",
                    "#text": "dcgiDau"


locenter.centers["@id"] / locenter.centers["#text"]



You may get this in chrome: getjson pound sign Uncaught SyntaxError: Unexpected token ILLEGAL

Cache output for ashx

Sometimes we use generic handlers to grab JSON or XML data and then use that data somewhere else. The problem you run in to is everytime you load the page you are making a call to that handler and the handler goes to that external data source and brings your data back to the client.

Here is a way to cache the data in IIS for a determined amount of time before you go back out and get new data.

In the ashx file:

public class WeatherHandler : IHttpHandler
     public void ProcessRequest(HttpContext context)
       TimeSpan freshness = new TimeSpan(0, 0, 0, 10);
       DateTime now = DateTime.Now;

       using (WebClient webclient = new WebClient { })

OR for all ASHX’s, you can put it in the web.config:

      <caching enabled="true">
          <add extension=".ashx" policy="CacheForTimePeriod" duration="00:00:10"/>