Tuesday, 16 February 2016

SharePoint: How do I get the groups for the current user in Javascript or JQuery?

My current project requires me to identify the persona of the logged in user based on their membership of specific SharePoint groups. The first port of call is to extract all the groups for the current user and then work out what they can do.

Sounds easy enough.

I tried the following:

function getUserGroups(success, failure)
var d = $.Deferred();

var ctx =  SP.ClientContext.get_current();
var collGroup = ctx.get_web().get_siteGroups();
                ctx.load(collGroup, 'Include(Users)');
var currentUser = ctx.get_web().get_currentUser();
var o = { d: d, collGroup: collGroup, currentUser: currentUser };

function onQuerySucceeded() {

var data = {
"collGroup": this.collGroup,
"currentUser": this.currentUser

//return success(this.collGroup);
return success(data);
function onQueryFailed(sender, args) {
console.log('Request failed in getUserGroups. ' + args.get_message() + '\n' + args.get_stackTrace());
return failure();

        ctx.executeQueryAsync(Function.createDelegate(o, onQuerySucceeded), Function.createDelegate(o, onQueryFailed));

but I got a permission error in 'ctx.load(collGroup, 'Include(Users)');'

The SharePoint groups were all set to 'Everyone can view membership', so I was stumped. I looked for a new solution to the problem and eventually settled on using SP.Services to get data:

var currentUser = 'ME' // Change this appropriately

  operation: "GetGroupCollectionFromUser",
  userLoginName: currentUser,
  async: false,
  completefunc: function(xData, Status) {
$(xData.responseXML).find("Group").each(function() {
// The Group ID is $(this).attr("ID")
// The Group Name is $(this).attr("Name"));

Monday, 8 February 2016

SharePoint 2010: How do I download a wsp?

I recently had the requirement to move a wsp from one farm to another and the source component was nowhere to be seen.

I found a nifty little script here that gave me a solution:

$farm = Get-SPFarm
$file = $farm.Solutions.Item("mycode.wsp").SolutionFile

Thursday, 4 February 2016

SharePoint: Why is my WEBDAV connection so slow?

Writing solutions using JQuery/Angular/Javascript is great. I use NotePad++ as my IDE and simply update the files on the SharePoint site directly.

Using IE, I use the 'Open in Explorer' option in the ribbon and edit the files directly.

However, the upload performance on my home PC really sucked. I was uploading a 500 bytes (yes bytes) a second. Painful.

The solution was pretty simple; uncheck 'Automatically detect settings' in the LAN Settings.

SharePoint: The language is not supported on the server

My current requires nested sub webs to have a specific language/regional setting. The problem arose when I started changing the Regional Settings from English (US) to English (Australia).

$web = Get-SPWeb $siteCollectionUrl


      myWeb.Locale = System.Globalization.CultureInfo.CreateSpecificCulture("en-AU");

However, this started to cause problems when users started to create their nested webs.

I was using the following C# code to create the webs:

var newWeb = web.Webs.Add("Name","Title", "My Web", site.RootWeb.RegionalSettings.LocaleId, webTemplate, false, false);

The locale I was referencing (3081) is not installed on the server - only the default 1033. It was trying to create new the site using the regional settings I had set previously. This was a bit of a problem: I need to create  the site and ensure the correct regional settings.

The 'hack' solution was to force the subsite to use 1033 and then change the locale afterwards.

var newWeb = web.Webs.Add("Name","Title", "My Web", 1033, webTemplate, false, false);
newWeb.Locale = System.Globalization.CultureInfo.CreateSpecificCulture("en-AU");