SharePoint import User Profile photos on a schedule

-command “& { Add-PSSnapin Microsoft.SharePoint.Powershell; Update-SPProfilePhotoStore -CreateThumbnailsForImportedPhotos 1 -MySiteHostLocation http://mysiteUrl}”

Posted in PowerShell, SharePoint

Using SelfSSL to generate a self signed certificate for IIS

selfssl /T /N:CN=*.spapps.local /V:1000 /S:

Posted in Uncategorized

Programmatically checking if a user belongs to an SharePoint Audience

The following code will check if a user belongs to a given Audience in SharePoint

using (SPSite elevatedSite = new SPSite(Microsoft.SharePoint.SPContext.Current.Site.ID))

    SPServiceContext serviceContext = SPServiceContext.GetContext(elevatedSite);
    AudienceManager audManager = new AudienceManager(serviceContext);
    Audience audience = audManager.GetAudience("AudienceToCheck");

    SPUser user = SPControl.GetContextWeb(Context).CurrentUser;

    if (audience.IsMember(user.Name))
          // do some stuff
Tagged with:
Posted in SharePoint, Uncategorized

Disable SharePoint ribbon control based on user list permissions

I had a requirement to create a button on a SharePoint list ribbon that was only enabled for Contributors of that list. The post will explain how to set that up in javascript using the SharePoint 2010 Client Object Model.

I assume that you already have knowledge of working with the Ribbon in SharePoint 2010 and in particular using javascript page components. The snippets assume you have the rest of the ribbon definition in place and an existing page component file. If you don’t, I’d recommend you head on over to Chris O’Brien’s great articles on ribbon customisations.

Creating the button.

First up we need to declare the button we wish to disable or rather enable based on the users permission.

  ToolTipDescription="Configure merge" />


The above definition is just that of an ordinary ribbon button, nothing special is declared in there.

Javascript page component.

The next step is to modify our page component file.

canHandleCommand: function (commandId) {
      if(commandId === 'Ribbon.MyButton.Button.Configure')
            if(userIsContrib == null)
                return false;
                return userIsContrib;
        else {
            return false;

var userIsContrib = null;

function checkUserIsContrib() {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    list = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());


    context.executeQueryAsync(Function.createDelegate(this, gotUserIsContrib), Function.createDelegate(this, failedUserIsContrib));

function gotUserIsContrib() {

    // update the variable based on the users permission
    userIsContrib = list.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems);

    //Update the UI


function failedUserIsContrib() {
    alert("failed failedUserIsContrib");


Because we want to check the user permissions asynchronously, we need to set userIsContrib initially to null. This will disable the button for all users while the checkUserIsContrib() method goes off and checks the users permissions.

After checking the users permissions and settings the flag appropriately we call RefreshCommandUI() which will again cause canHandleCommand to be run again. This time it will return the value that was set in the gotUserIsContrib() method. As a value has now been set on userIsContrib, no more checks against the server will be made by any other calls to RefreshCommandUI.



Tagged with: , , ,
Posted in Uncategorized

Package class library as wsp for SharePoint Deployment

Some Visual Studio solutions I’ve come across have class library projects in them. These assemblies have to subsequently be manually copied into the GAC of each SharePoint server. This goes against the standard of using wsp files to deploy assemblies and files into a SharePoint environment. Single servers are easier to manage manually copying assemblies but it’s not a very pleasant way of doing things, move into a multi server environment and you’re in a minefield.
Fortunately there is an easy way to get these assemblies, plus any others you may wish to deploy at the same time, into a wsp. It takes two files and a post build event. Read on..

First up, we need a manifest file. This tells the environment what we would like it to do with the assembly.
Create a new xml file in the root of your project called manifest.xml and add the following code:

<solution xmlns="" solutionid="">
    <assembly location=".dll" deploymenttarget="GlobalAssemblyCache">

Replace <new guid> with a generated GUID and <assembly> with the name of your dll file.
The DeploymentTarget attribute above specifies that it will be deployed to the GAC, you can use WebApplication if you want it to be deployed to the bin directory of your Webb Application.

You can also specify that the relevant line can be added to the SafeControls section of your web.config file by adding the following inside the Assembly tag above.

        <safecontrol assembly=", Version=, Culture=neutral, PublicKeyToken=
" namespace="" typename="*" safe="True">

Next up, create a ddf file in the root of your project. I tend to name mine wsp.ddf for consistency. This will contain the instructions on what to package into the wsp file. This file should look like the following.

;Define the output directory and CAB file name (with a wsp extension)
.Set DiskDirectory1="bin\Debug"
.Set CabinetNameTemplate="MySolutionName.wsp"

;Include the following files in the CAB Root

Now all we have left to do is add a post build event to build the wsp for us.
Go to you project properties (right click project)
Under the Build Events tab under Post-build event command line, enter the following:

:: Change directory to the root of the project
cd "$(ProjectDir)"

:: Create a WSP CAB
MakeCAB /f "WSP.DDF"

You can change when the post build event runs, to your liking; normally ‘On successful build’.

That’s it when you have a successful build the wsp file will be generated ready for you to deploy, no more manual copying or editing web.config.

Tagged with:
Posted in SharePoint

Arrays in custom web part and SharePoint Designer

I came across an issue when trying to add a custom web part to a page layout in SPD.
Each time I added it, the web part would error “Cannot create an object of type ‘Systems.Collections.ArrayList’ from its string representation ‘Collection’ for the ‘MyValue’ property”.
I narrowed it down to an ArrayList I had declared as public within the webpart. Changing this from public solved the issue for me.

Tagged with:
Posted in SharePoint

Required Field Validation Group on PeopleEditor control

Very similar to my post on validation of the DateTimeControl, a PeopleEditor (people picker) control I was using was validating on each postback.
I created a required field validator with a ValidationGroup and to get the validator to look at the correct people editor field use the following code.

myRequiredFieldValidator.ControlToValidate = string.Format("{0}$downlevelTextBox", myPeopleEditor.ID);
Posted in Uncategorized

Get every new post delivered to your Inbox.