Add AD-Group to SP2010 via CSOM

Unfortunatly, projects aren’t always that fancy. In this case I’m still doing a bit of SP2010. Luckaly we do use CSOM to make it a bit interesting.
CSOM has a lot of functionality, and theoretically you can say “it does everything the old-fashioned SPSite model does”. However, it can be a struggle.

In this case, we needed to add a AD Group/User to sharepoint directly. Don’t ask, it’s a customer requirement. So, no SharePoint groups used.

In the end, this MSDN article was hugely useful.

Also note the usage of EnsureUsers which seems to work for groups as well!?

The permission parameter are the “Full Control” or “Read” permissions which are called “Permission Levels” in SharePoint itself. There’s a “level” below that called BasePermissions, for if you want to make it more complex for yourself :)

Here’s the bit of code that works for me:

        public static void AddSecurityGroup(string url, string loginName, string permission)
            using (ClientContext context = new ClientContext(url))
                context.Load(context.Web, w => w.RoleAssignments);
                context.Load(context.Web, w => w.HasUniqueRoleAssignments);
                if (!context.Web.HasUniqueRoleAssignments)
                    throw new ArgumentException("URL provided is not root for permissions. Did you break inheritence correctly? Because that's needed.");
                User u = context.Web.EnsureUser(loginName); //This also seems to work for groups.
                context.Load(u); // important as this actually loads the properties etc.
                RoleDefinition oRoleDefinition = context.Web.RoleDefinitions.GetByName(permission); 
                RoleDefinitionBindingCollection collRoleDefinitionBinding = new RoleDefinitionBindingCollection(context);
                RoleAssignment oRoleAssignment = context.Web.RoleAssignments.Add(u, collRoleDefinitionBinding);

Happy coding!

K2 smartforms custom theme tips

So, it’s been a while since i’ve written something. Yes, i’m still alive – a lot has happened in personal and professional life!
With K2 smartforms already being at release 1.0.4, it’s about time I wrote something about it!

A lot of customers are using a custom theme to create forms that are in their company’s style/look&feel.
There’s an article on how to create a theme, but here’s my version of it:

  • Copy one of the themes in “C:\Program Files (x86)\K2 blackpearl\K2 smartforms Designer\Styles\Themes” to a new folder, which has the name of your theme.
  • Copy the CSS file with the same name, into a new file with the name of the newly copied directory. This will be your theme name.
  • Do the same for the C:\Program Files (x86)\K2 blackpearl\K2 smartforms Runtime\Styles\Themes folder and CSS file.
  • Add the theme name to the K2 database. Insert into the Form.Theme table. Only the name is enough!
  • SmartForms is heavily cached for performance. This cache causes theme changes not to show up. Disable this cache by changing the Forms.CombinedResources.Cache.Enabled value to False in the web.config of both the design and runtime site!
  • Recycle the application pool, or do an IISRESET.

And that’s basically it! If you want to quickly change some colours, there’s also a K2 smartforms theme builder on the K2 underground.

Happy smartforming!

K2 SmartObject Services – Configuration update, static endpoint

After the release of K2 1370, there have been some small updates to the K2HostServer.config file for your SmartObject Services configuration.

The basics is pretty simple, KB1370 added the ability to change binding and binding configuration on the REST and WCF endpoints separately. Because the binding configuration also defines the authentication mechanism, this means that REST endpoints could use basicHttpBinding with Basic authentication, while the WCF endpoint uses wsHttpBinding with Windows authentication. It also allows us to run either one endpoint on HTTPS while the other is not.

In my previous post on the K2 Services I showed you how to create a static endpoint, this simplifies the URL and allows you to rename or update the SMO without the endpoint changing. The configuration sections shown in those posts are now outdated and won’t work anymore. Since the KB article describing the change doesn’t have all the parameters, this post is also a note-to-self.

Read more »

WordPress Themes