Working with the TaxonomyClientService: Part 4 – Populating Values with the Lists web service

So far I’ve discussed how to get information about getting the types of taxonomy field, working with those fields, and how to get term sets. What about setting values on list items?

It isn’t immediately obvious how to do that. For a start, we wouldn’t actually be using the TaxonomyClientService. To set values on items, you use the Lists web service, using the UpdateListItems() method. This accepts XML describing the field and values.

But what fields do we submit, and what values? After all, as mentioned in part 1, there are two fields – one for the displayed value, and a hidden ‘notes’ field that contains the actual data!

There was no documentation about how to set these values, and limited and contradictory information in blog posts, so I investigated…

Continue reading “Working with the TaxonomyClientService: Part 4 – Populating Values with the Lists web service”

Working with the TaxonomyClientService: Part 4 – Populating Values with the Lists web service

Working with the TaxonomyClientService: Part 3 – Caching

In Part 2 of this series I described how to retrieve a TermSet, and interpret the results. I suggested using code:

string clientTimestamps = string.Format("<timeStamp>{0}</timeStamp>", lastClientCacheTime );
string clientVersion = "<version>1</version>";
string termStoreIds = string.Format("<termStoreId>{0}</termStoreId>", termStoreId.ToString("D"));
string termSetIds = string.Format("<termSetId>{0}</termSetId>", termSetId.ToString("D"));
string serverTermSetTimestampXml;
string result = _wssTax.GetTermSets(termStoreIds, termSetIds, 1033, clientTimestamps, clientVersion, out serverTermSetTimestampXml);

Fine, but what are these properties we’re passing into GetTermSets()? Continue reading “Working with the TaxonomyClientService: Part 3 – Caching”

Working with the TaxonomyClientService: Part 3 – Caching

Reminders on customising the RichTextField control in Publishing

Right, so, again I’m looking at the problem of consistent formatting of client authored text in SharePoint. (Incredibly, it’s 4 years since I first looked at this).

Anyway, as a note to myself… Continue reading “Reminders on customising the RichTextField control in Publishing”

Reminders on customising the RichTextField control in Publishing

SPWeb.Properties serialization in the Sandbox

I was trying to store and retrieve some properties on an SPWeb object inside the sandbox. SPWeb has SetProperty() and GetProperty() methods, which accept and retrieve objects. I thought I’d use an enumeration to represent my value, and I’d cast my enumeration value when I retrieve it. However, when I tried this I got an exception of the form:

System.Runtime.Serialization.SerializationException was unhandled Message=Unable to find assembly ‘<my assembly strong name>’

Interesting. I tried similar code within a Console application using the full SharePoint API… Continue reading “SPWeb.Properties serialization in the Sandbox”

SPWeb.Properties serialization in the Sandbox

MissingMethodException when calling SPWeb.Recycle() in Sandbox solution

Service Pack 1 for SharePoint 2010 introduced a new method for the SPWeb object – Recycle(). This allows you to send a site to the recycle bin, rather than deleting it outright. I’ve used it before in Farm solutions without any issue.

However, I’m now working on a sandbox solution, and when I tried using it, I got the error:

MissingMethodException Method not found: ‘Void Microsoft.SharePoint.SPWeb_SubsetProxy.Recycle()’.
at Microsoft.SharePoint.SPWeb.Recycle__Inner()
at Microsoft.SharePoint.SPWeb.Recycle()

Hmm. That’s strange; my call to recycle seems fine, and the documentation says it’s available in the Sandbox, but internally there seems to be a missing method.

Out of curiousity, I tried using Delete() rather than Recycle(), and this worked correctly. So what gives? Continue reading “MissingMethodException when calling SPWeb.Recycle() in Sandbox solution”

MissingMethodException when calling SPWeb.Recycle() in Sandbox solution

No CssRegistration control in Sandbox

Hmm – and interesting problem; in the Sandbox you don’t have any access to the CssRegistration class. It’s in the Microsoft.SharePoint.WebControls namespace, and you don’t have access to that.

So, what do you do to link to an external stylesheet? Um, well, there isn’t any pretty story. The best I’ve come across is by Ian Chivers, who uses JavaScript to add another <Link> tag into the <Head> of the page.

Clever, but yuck! Continue reading “No CssRegistration control in Sandbox”

No CssRegistration control in Sandbox

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(&quot;My Monitored Scope&quot;))
{
    // 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