Sandbox Development – Reference the User Code DLL

Remarkably, I’ve only just started doing my first Sandboxed development in SharePoint 2010. (Most of our customers own their own servers, and want functionality you can’t easily build in the Sandbox alone).

Anyway, I knew that the API you could use in the sandbox was smaller than the full API, and I wanted my solution to warn me (e.g. fail to compile) if I tried to use something that wasn’t available in the sandbox. I found two approaches… Continue reading “Sandbox Development – Reference the User Code DLL”

Sandbox Development – Reference the User Code DLL

Using SPMonitoredScope, Counters and SPCriticalTraceCounter

Something that I don’t always remember – you can use the SPMonitoredScope class to monitor your SharePoint code as it executes. The results then get sent to the Developer Dashboard and ULS logs. There’s a decent description of it on MSDN.

using (new SPMonitoredScope("My Monitored Scope"))
{
    // Do Stuff...
}

Continue reading “Using SPMonitoredScope, Counters and SPCriticalTraceCounter”

Using SPMonitoredScope, Counters and SPCriticalTraceCounter

Check Permissions in JavaScript Client Object Model

I had a need to check the rights a user had on a particular item in SharePoint. Unfortunately, this had to be done entirely client side. Naturally, I turned to the client object model – but it took a little time to figure out.

I wanted to query for a particular item, some (though not all) of it’s properties, and I wanted to get it’s permissions. This post by Henrik Andersson gave me a good clue, though it didn’t explicitly mention getting the properties. To get the item, with it’s properties and it’s permissions:

//var clientContext = new SP.ClientContext(.... ;
clientContext.load(listItem, 'EffectiveBasePermissions', 'ID', 'Title', 'Owner', 'Active', 'Modified', 'Editor');
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnItemQueryCompleted), Function.createDelegate(this, this.OnItemQueryFailed)); 

That performs the query to get the item and permissions – but how do you check them? Well, you need to to use the SP.ListItem.get_effectiveBasePermissions() method. (Note: there are SP.List.get_effectiveBasePermissions() and SP.Web.get_effectiveBasePermissions() methods too, for those tiers of the hierarchy).

function OnItemQueryCompleted(sender, args) {
	var perms = listItem.get_effectiveBasePermissions();

	if (perms.has(SP.PermissionKind.editListItems)) {
	      // ....
	}
}

The permissions are retrieved into an SP.BasePermissions object, which has the .has() method that you can use to check the permissions (returns true if the user does have that permission). The Permissions mask is defined by the values in the SP.PermissionKind enumeration.

Check Permissions in JavaScript Client Object Model

Handle Exceptions in Client Object Model callbacks

A note to myself, of something I found on MSDN – for the ‘failed’ function on an asynchronous JavaScript call in the SharePoint Client Object Model:

function OnItemQueryFailed(sender, args)
{
   alert('Error:n' + args.get_message() + 'n' + args.get_stackTrace());
}

Note that these details are from the SP.ClientRequestFailedEventArgs class. There are other properties too.

Handle Exceptions in Client Object Model callbacks

Working with the TaxonomyClientService: Part 2 – Get the TermSet (and understand it!)

In Part 1 I looked at the structure of our Taxonomy field – which is in fact two fields. We also saw how the TaxonomyField definition has an array of properties related to it too. As a reminder, here’s a screenshot of the XML for it:

These properties are quite important, as they tell us what we need to know to get the correct TermSet for our field. Continue reading “Working with the TaxonomyClientService: Part 2 – Get the TermSet (and understand it!)”

Working with the TaxonomyClientService: Part 2 – Get the TermSet (and understand it!)

Working with the TaxonomyClientService: Part 1 – What fields are there?

I have been working on an integration that needs to read terms from SharePoint’s Managed Metadata service, for a particular field, and then populate that field with those values. All this has to be done via SharePoint’s web services – so the relevant ones here are the TaxonomyClientService, and Lists web service.

This has proved particularly bloody hard. Continue reading “Working with the TaxonomyClientService: Part 1 – What fields are there?”

Working with the TaxonomyClientService: Part 1 – What fields are there?

SafeControls Entries in Manifest can be changed during deployment

I had a slightly unusual situation. We’ve a customer who has using the Telerik RadEditor version 4.5.6 for SharePoint 2007. They’re upgrading to SharePoint 2010, and want their existing content to continue to work.

They’ve using the Telerik RadEditor web part quite a lot, so we had to keep that working. We’ve put in Assembly Binding Redirects using an SPWebConfigModification (more on that in a later post).

However, we also needed to put in the SafeControl entry for the old assembly. Continue reading “SafeControls Entries in Manifest can be changed during deployment”

SafeControls Entries in Manifest can be changed during deployment

Run SPDisposeCheck as part of your build process

As mentioned before, I’ve been automating the building and analysis of our SharePoint code, and this led me to ask, can you run SPDisposeCheck as part of a TFS build process?

Yes we can. Richard Fennell has a concise and simple description of how to do it. It’s best to read that, but in case that site goes down, the short of it is – use InvokeProcess to run SPDisposeCheck, and it’ll return a value that is the number of errors/warnings it finds. I find that that’s enough to choose whether to write a warning to the output of the build, and I don’t then parse and write the individual warnings into the build. These should be captured by the build log, and they’re pretty obvious, so it doesn’t seem worth the hassle. You could do it if you really wanted to.

Don’t forget you can use attributes to prevent false positives – though I still have issues with anonymous delegates that are false positives (how do you add the attributes?), and that’s what’s causing the two warnings above.

Run SPDisposeCheck as part of your build process

Error: 'b' is null or not an object

This error has caused me so much pain when trying to use SharePoint’s JavaScript client-side object model (CSOM), so, in case I have it again:

  1. Check that the function exists.
  2. Check that the function is named correctly.
  3. Make sure that you’re not using “this” in the call to createDelegate, as detailed here.
    • Right: Function.createDelegate(this, onSuccessMethod)
    • Wrong: Function.createDelegate(this, this.onSuccessMethod)

    I don’t know why this difference should cause this error, but I’ve proved it true.

If you know of other causes of this error, let me know, I’ll add it to the list. I love the experience of debugging JavaScript…

Error: 'b' is null or not an object