Archive for the ‘development’ Category

List of JS Libraries I’m using / looking into

July 3rd, 2014 Comments off

This is more of a note to myself so that I can remember the JavaScript libraries I’m interested in and what they do and maybe a related article.  These are mainly in dealing with SharePoint but could be anything really.  Not everything is compatible with everything else remember :-)


KnockoutJs – Data binding library, works with jQuery, great for a true single page app, IE no routing just data binding.  Yes I know SPA’s pages are called views.

AngularJS – Proper SPA framework, there’s Durandal but I’?m not going there even though I love knockout.


    - Linq Like queries, does need server side integration, not for local objects

Bootstrap – For that nice CSS layout grids and things.

Bootstrap UI – Directives for Angular using bootstrap

Angular Maps – Google maps directives for angular, something I’ve used already.


LinqJs – Linq for JavaScript, will work on JS objects, doesn’t do fetch for you

Js Loaders –  and

jQuery – Well how could I not mention it.

jQuery form validators

Sliders – ,,

fontawesome – No idea, well something to do with a shed load of CSS icons, vectors (no IE7)

Charts – jqPlot,, hicharts

Spinner - svg/vml Spinner, easier than a gif ?


Stuff to investigate

  • d3js – Don’t know why or what this gives me over anything else yet.
  • threejs – 3d library, gotta have some fun sometime.
  • Mobile Angular frameworks


Not a library but a list of handy SP2013 dev tools

Zimmergrens SP2013 Tools Page

God Ted, I love fiddler – or using fiddler to address individual servers on a HNSC)

April 25th, 2014 Comments off

This tool just gets better for me with every little bit more I learn about it. I use it as a proxy server for my VM’s to keep them of the main network, but have internet access. I use it for speed tests, I use it for dynamic debugging of javascript of sites I have no access too.  It’s wonders do not cease.

Yesterday I had an problem with a Host Named Site Collection, or rather it appears that one of the servers appeared to be slow.  But being a HNSC no AAM’s were created for it and with four front ends to test how the hell do you hit each one sseperately.

Chap running the servers was kind enough to give me the IP addresses and of course I can then edit the hosts file and test each one from the main address.

Well that sucks.

Enter Fiddler, did I say how much I love fiddler ?

In fiddler is a rules file,   CTRL-R will get you there. In that we can do marvelous things, in this case I wanted to handle my HNSC problem by having 4 separate urls I could hit and test each server in a load test script.

My host was something like

and I wanted to hit


Here’s how to do it in fiddler.  Edit the rules file and find the function OnBeforeRequest, its all javascript dontcha know.

Add this bit of code at the bottom of the function

<pre>         if (oSession.hostname == ""){
             oSession.hostname = "";
             oSession["x-overrideHost"] = ""; // <-- Server IP here!
         if (oSession.hostname == ""){
             oSession.hostname = "";
             oSession["x-overrideHost"] = ""; // <-- Server IP here!
         }         if (oSession.hostname == ""){
             oSession.hostname = "";
             oSession["x-overrideHost"] = ""; // <-- Server IP here!
         }         if (oSession.hostname == ""){
             oSession.hostname = "";
             oSession["x-overrideHost"] = ""; // <-- Server IP here!

Save it and do a test.

I even ran WireShark to see what was actually happening on the network stack, and it works, it was routing requests for specific servers to each individual server, and because we set the hostname to what it should be any code JS or server using the server name works fine too.

Makes me really want to crack open the fiddler manual and find out what other voodoo I can do.

Categories: development, Internet, Sharepoint Tags:

SharePoint Apps and AngularJS – SP.WebProxy Invocation using promises

April 17th, 2014 1 comment

Recently I’ve been trying to create a SharePoint 2013 app using AngularJS and angularui-bootstrap.

It’s been going well thanks to Jeremy Thake’s (@jthake) original demo.

But I wanted more! More than just access to the local site, I wanted access to the web, but I wanted to do it in the right AngularJs way, using the service so later when I figure out how to do DI testing I can, using promises too, which of course SharePoint doesn’t return in a way we can use in AngularJS.

So this code snippet (not complete app) will give you a clue on a way of doing it, there may be a better way to do this in AngularJS Im no expert, I see references to moduile.Factory calls in other examples, but I’m sticking to Jeremy’s starter code for now.

This example uses UK police data, details of the license are here

'use strict';
var myApp = angular.module('myApp', []);

function myAppCtrl($scope, $myDataService) {
    $scope.getPoliceClick = function () {

        //Whoops, edited this line as it was wrong from original post
        var promise = $myDataService.getPolice($scope);
            //Success callback, check the status = 200 and go mad
            function (response) {....
            //Epic Fail callback
            function (response) {....

//this method signature is same as Jeremy's thats why the $http is there, I use it for lists as well
//just not in this code sample
myApp.service('$myDataService) ', function ($q, $http) {
    this.getPolice = function ($scope) {
        var deferred = $q.defer();
        var context = SP.ClientContext.get_current();
        var request = new SP.WebRequestInfo();
        // We need the response formatted as JSON.
            "Accept": "application/json;odata=verbose"
        var response = SP.WebProxy.invoke(context, request);
            function () {
                //Notice the scope apply, because the async call is made from outside of angular
                //just resolving will not work
            function () {
        return deferred.promise;
Categories: development, Sharepoint Tags:

SharePoint 2010/13 Getting the Default Disp Page in JSOM

April 10th, 2014 Comments off

Being pretty new to JSOM, thought I might write this down so I don?t forget again.

JSOM is just quite a bit different to REST or SPServices or just ferreting around the old server API, so it’s going to take some time.  Give me REST any day, but today I find myself altering some one else’s code.

I needed to find the default display page Url

Well it’s pretty simple, but web examples are gathering all list information the code I had was getting a specific list, not sure that they are still not getting all lists, but hey.

Adding the paramter “Include(DefaultDisplayFormUrl)” into the getByTitle function, instructs CSM that you want this bit of info.




 targetList = clientContext.get_web().get_lists().getByTitle("Glossary", "Include(DefaultDisplayFormUrl)");  



But you can’t access it immediately.

No you have to wait until after the executeQueryAsync only then can you call the function on the targetList variable, so watch those scopes,


  targetList = clientContext.get_web().get_lists().getByTitle("Glossary", "Include(DefaultDisplayFormUrl)");  
      Function.createDelegate(this, function() { alert( targetList.get_defaultDisplayFormUrl();) } ),
      Function.createDelegate(this, function() {alert("failed")})

Technorati Tags: ,,

Categories: development, Sharepoint Tags:

Using jQuery Queue with SPServices

November 20th, 2013 3 comments

One of the problems I came across the other day is I had several hundred items in a list to process.  To make life easy I use javascript on a web part page to make an app to process the items I wanted to do. 

However when its hundreds, do them all at once and you’re in trouble.  You block the UI thread, you cant update any status values, I dare not think what would happen if you called a couple of hundred async ajax queries all at once, it might just handle them – you can try it if you want ;-)

To get round this I thought I’d try to use jQuery queues.  So in this example I have a custom list which I get data from, I’m using promises to get the data but there was no need, I just used some code from the last example.  Once I have the data I inject it onto the screen an lose the original data array (now this is the point where I should use knockout and let the screen adjust to the observed data, but this is a demo).  Then on a click event, a big process this now button, I iterate thru each item on the page, gets its details and add a function to the queue that calls another function (just for being tidy I could embed) which makes a call to SPServices async update, phew.

Then I tell the queue to start executing the functions in it, one at a time.  At the end of each async success, it calls the next function, you might spot the mistake here, what if it doesn’t succeed (well I forgot to code it, but you need to do something with the item and the queue when you do it).

Hint: When calling functions and sub functions, make sure you “var” every variable, I forgot and it only updated the last item.

Technorati Tags: ,,

Here’s the code


 <script src="js/jquery.SPServices-0.7.1a.min.js"></script>  <script src="js/underscore.min.js"></script>   <div id="mainApp" > 	<div id="appStatus">Initialising</div>	<div id="appButton" style="cursor:hand;display:none">Click Me</div> 	<div id="appBody"></div>  </div>        <script>

var binaryJamQueueTest = function ($) {
   	//Private Members
  	var testListArray;

	function main() {

		//Remember that $.when is an async function also, so dont put anything after this code
		//unless you want it running immediately, in which case stick it here first.
		.fail(function() {
  	function loadFailure() {
  		//Oh dear
	  	$("#appStatus").text("Failed to Load data");
  	function dataReady() {
  		$("#appStatus").text("Processing Data");
  		//Earlier versions did not queue so in cases where you will thread block
  		//use something like this to give the DOM time to update
  		setTimeout(function() {
	  	}, 10);
  	function asyncGetTestList() {
  		var dfd = $.Deferred();
			operation: "GetListItems",          
			async: true,          
			listName: "TestList", 
			CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='name' /><FieldRef Name='valueField' /></ViewFields>",

			completefunc: function(data, status) { 
				if (status== "success") {
							return {
								id: $(this).attr('ows_ID'), 
		                        title: $(this).attr('ows_Title') , 
		                        name: $(this).attr('ows_name') ,
		                        value: parseInt($(this).attr('ows_valueField')) 
		return dfd.promise();
  	function updateListItem(id, title, value, $item, next)
		//Notice here, if I was databinding I would only have to update the value not the html item
			operation: "UpdateListItems",
			async: true,
			ID: id,
			listName: "TestList",
			valuepairs: [ ["valueField", value]],
			completefunc: function(xData, Status) {
				$item.text(title + " " + value);
				$item.attr('value', value);
  	function processList()
		var $taskQueue=$({});
  		var htmlAdd="";
		$.each(testListArray, function(locIndex, testListRow) {
				htmlAdd+="<li id='" + + 
								"' title='" + testListRow.title + 
								"' name='" + + 
								"' value='" + testListRow.value + 
						  "'>" + testListRow.title + " " +
						 testListRow.value + 
		//Clear the original list Im going to use stuff onscreen, I know its wrong and not MVC
		//But Hey you do it the right way with a data binding library instead
  		html=$("<ul id='itemsToProcess'>" + htmlAdd+ "</ul>");

  		$("#appButton").click(function() {
			$.each($("#itemsToProcess").children(), function() {
				var $currentLi=$(this);
				$taskQueue.queue('tasks', function(next) {
	  				var id =$currentLi.attr('id');
	  				var title =$currentLi.attr('title');
	  				var value=parseInt($currentLi.attr('value'));
	  				updateListItem(id, title, value+1, $currentLi, next );


	//Public Members
  	return {
   		init : main

}(jQuery); //binaryJamQueueTest Module

jQuery(function () {


Categories: development, Sharepoint Tags:

Error When talking to SharePoint Web Services in code

January 4th, 2012 1 comment

I’ve been trying to talk to SharePoint’s web services in C# for a couple of hours now. Something I do in JS all the time, but rarely in a clients C# app.

I’ve been getting the same error over and over again, but keep getting an error when trying to do anything.

Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

I had dutifully copied the example code from the MSDN site and got a web reference to the Lists Web Service of course

and commented out the URL code in the example because that points at their site, not mine, which is pointed to by my web reference.

/*Set the Url property of the service for the path to a subsite.*/ listService.Url = http://MyServer/sites/MySiteCollection/_vti_bin/Lists.asmx;


If you are getting this error then it is because you commented out the URL.

When you add a web reference you are adding a WSDL file which is then compiled.  The WSDL is not specific to your site location,

if you open up the WSDL XML the section right at the bottom is pointing to elsewhere, the root of the WebApplciation not the RootWeb / Site you are interested in.

<wsdl:service name="Lists">     <wsdl:port name="ListsSoap" binding="tns:ListsSoap">       <soap:address location="" />     </wsdl:port>     <wsdl:port name="ListsSoap12" binding="tns:ListsSoap12">       <soap12:address location="" />     </wsdl:port>

You need that line in the code that sets the listService.Url value, without it you are going to go mad trying to track down this bug, cos I didn’t find the answer online, I had to use fiddler.  Of course this article will now exist. :-)


Categories: development, Sharepoint Tags:

Creating TFS task Items from Powershell – From SPDisposeCheck Output

May 27th, 2011 Comments off

Now one for the SharePoint people.  You have ran SPDisposeCheck on the dire piece of code your lackey wrote (or youself for that matter) and forgot to run the SPDisposeCheck.  Whoosh loads of entries to validate and change the code for. 

Being good people using TFS for source code and task management you want an entry for each item to check.

Using the built in XML handling facilities from PowerShell this is an easy task.

First run SPDisposeCheck with the output set to XML You will get something like this

<?xml version=”1.0″ encoding=”ibm850″?>
<ArrayOfProblem xmlns:xsi=”” xmlns:xsd=””>
    <Assignment>local2 := new Microsoft.SharePoint.SPSite(local0).{Microsoft.SharePoint.SPSite}get_RootWeb()</Assignment>
    <Notes>Constructor called for Microsoft.SharePoint.SPSite but not assigned. This type should be assigned and subsequently disposed</Notes>


You can Easily read XML files in PowerShell with a simple statement

$xmldata = 1(Get-Content c:\test\out.xml)

Accessing the Elements is then just object notation


Will return an array of problem items that can be accessed in a foreach $problem and with $problem.ID

So the full code to do this is

Read more…

Categories: development, Sharepoint Tags:

jQuery autocomplete for SharePoint Search Box

December 6th, 2010 3 comments

Whether or not SharePoint actually needs an autocomplete for it’s search box could be debated, and the manner in which I’m about to implement it, well that could be debated also. 

The point of this post was to use jQuery techniques to query a list via its web services and do something flash.  I’m doing it SharePoint 2007 as that is what I have handy and working. 

I will be upfront and honest right now, the code for this is a Mashup from two sources, Jan Tielens and the jQueryUI demo itself, both needed tweaking to come up with something new, but just so you know it’s not been rocket science, hard work was done for me, cheers Jan. 

Read more…

WSS3 – ItemAdded – deadlocked on lock

February 12th, 2010 3 comments

I’ve been having a problem with an app I wrote.  It works great, 99% of the time, but sometimes the ItemAdded event appears not to fire.

Now this is using a list with over 20,000 entries in it and its growing all the time.  An associated list that references this list as a lookup has over 144,000 entries in it.

The event firing problem is becoming more frequent now as more users start using the system, there are at least 20 occurances in that 20,000 items, so it has to be fixed.

Managed to track down an error in the log

System.Data.SqlClient.SqlException: Transaction (Process ID 61) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

It’s stack trace was similar too this (I cut it down a bit and changed some names, my naming is not this bad)

at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()
   at Microsoft.SharePoint.SPListItemCollection.get_Item(Guid uniqueId)
   at BinaryJam.Core.Code.TicketListReceiver.ItemReceiver.ItemAddedActual(Guid SiteId, Guid ListItemId, String UserDisplayName)
   at BinaryJam.Core.Code.TicketListReceiver.ItemReceiver.<>c__DisplayClass11.<ItemAdded>b__e()
   at Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state)
   at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()
   at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
   at BinaryJam.Core.Code.ItemListReceiver.ItemReceiver.ItemAdded(SPItemEventProperties properties)

So as you can see, it explodes on the GetItem.

This was my stupid mistake, a mistake I bet many of you are making every day.

SPListItem item = List.Items[listItemId];

This I believe is the primary cause of the problem as this statement loads the complete List before returning the specific item I needed and as this list grows, remember 20,000 items already, its going to get worse.  Now for most of you this won’t be a problem as you will be just getting the ListItem from the parameters, in my case I have to run as elevated as Im doing lots of stuff with Security Groups, that the entering user may not be in, hence my needing to re-get the List Item in the right security context.

So if your having a problem like this remember, Always use the

List.GetItemByID(id); //Or

This may or may not solve my problem I believe it will, if it doesn’t it’s still going to improve the performance of my application.  If your wondering, this is the only time I use this and don’t know why I did, the rest of the App uses getby id or SPQueries.

A Good Article on Performance I did actually read, hence the app performs pretty well, except for this one bug, which is now hopefully fixed.





WSS, Workflow, Who Actually approved this ?

November 5th, 2009 Comments off

So I like many have a workflow that takes requests for Sites with a bunch of details for costing etc.  Then when approved those Sites are created and permissions allocated.

What we did not have was a record of who actually approved the sites.  Whilst this info is in the workflow history after a while that information gets purged, leaving us with Sites that were approved but by whom we know not.

So this is a simple case of changing the workflow and recording all of the approvers in the SPWeb properties, except that the approvers as we can tell happen to be Sharepoint Groups or AD groups, neither of which contain a history of membership, if AD does none I know how to access and certainly not easy for the customer and in a large membership we still would not know who actually did the deed.

I dug and dug for this and eventually found the User Login that actually did the change and here is how.

In your workflow you need a “Workflow Action” of EventName “OnTaskChanged”, this object in the code behind, when Invoked contains AfterProperties,

string user = OnApprovalTaskChanged.AfterProperties.ExtendedProperties[new Guid("d31655d1-1d5b-4511-95a1-7a09e9b75bf2")].ToString();

The above statement gets the User Login frmo the ExtendedProperties Collection.  It Stores the User under the key of that Guid in a User type field that refers to the Editor.

A list of fields can be found here .

So that’s it, took a lot of debugging and poking about but next time your looking for the actual approving user, take a look here.

Categories: development, Sharepoint Tags: