Category: Development

Revoke Permissions from RoleDefinition

I had to revoke some of the permissions of a role definition but there’s no out of the box functionality to do so. After some searching on the web I couldn’t find any suitable methods either.
So I decided to create on myself and thought creating an extension method would be the best option.

/// <summary>
/// Revokes the given permission from the BasePermission set.
/// </summary>
/// <param name="roleDefinition">The role definition.</param>
/// <param name="revokePermission">The permission you want tor revoke.</param>
public static void RevokePermission(this SPRoleDefinition roleDefinition, SPBasePermissions revokePermission)
{
	// Remove space, because BasePermissions contains spaces between entries
	string originalPermissionsString = roleDefinition.BasePermissions.ToString().Replace(" ", "");
 
	// Split orignal permission entries
	string[] originalPermissions = originalPermissionsString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
	roleDefinition.BasePermissions = new SPBasePermissions();
 
	foreach (string originalPermission in originalPermissions)
	{
		if (originalPermission == revokePermission.ToString())
			continue;
 
		SPBasePermissions newPermission = (SPBasePermissions)Enum.Parse(typeof(SPBasePermissions), originalPermission);
 
		roleDefinition.BasePermissions = roleDefinition.BasePermissions | newPermission;
	}
}

After implementing this extension into your project/solution/class you can now revoke permissions from your permission set like this.

SPRoleDefinition roleDefinition = web.RoleDefinitions["YourRoleDef"];
roleDefinition.RevokePermission(SPBasePermissions.BrowseUserInfo);
roleDefinition.Update();

Create reusable site workflow in SharePoint Designer

Workflow development within SharePoint 2010 has become a lot better, I even worked with SharePoint Designer :D .
One off the things I particullary like is the ability to export your SPD created workflows and afterwards import it into Visual Studio, this developers to have the workflows created by someone else. And after the workflows are created the can be send to the developer(s) and used within the provisioning.
But unfortunatly you can not you are not able to export your site workflow in SPD because the icon is disabled.

Disabled save as template

Disabled save as template

After some research I’ve found a way to have an exported workflow to be imported into Visual Studio and used in the provisioning.
Just start creating your workflow as a reusable workflow within SharePoint Designer, after you’ve added all your actions and conditions you can use the Save as Template button to save your workflow into the Assets library in your site collection.
Create a new “Import reusable workflow” project in your Visual Studio.

Import reusable workflow project

Import reusable workflow project

After you have fully imported your workflow, click the icon to Show All Files Show all files in the solution exporer. You’ll now see all hidden files withi the solution explorer, now double click the SharePointProjectItem.spdata file. The file will look something like this.

<ProjectItem Type="Microsoft.VisualStudio.SharePoint.Workflow" DefaultFile="ReusableWF.xoml" SupportedTrustLevels="FullTrust" SupportedDeploymentScopes="Site" xmlns="http://schemas.microsoft.com/VisualStudio/2010/SharePointTools/SharePointProjectItemModel">
  <Files>
    <ProjectItemFile Source="Elements.xml" Target="ReusableWFFT" Type="ElementManifest" />
  </Files>
</ProjectItem>

After experimenting a bit with Visual Studio and the Site Workflow, I found the difference between the reusable workflow and the site workflow.
The difference was the follow piece of Xml.

  <ExtensionData>
    <ExtensionDataItem Key="WorkflowType" Value="Site" />
  </ExtensionData>

The ExtensionData element was present behind the element. After adding the ExtensionData element your Xml should look something like this.

<ProjectItem Type="Microsoft.VisualStudio.SharePoint.Workflow" DefaultFile="ReusableWF.xoml" SupportedTrustLevels="FullTrust" SupportedDeploymentScopes="Site" xmlns="http://schemas.microsoft.com/VisualStudio/2010/SharePointTools/SharePointProjectItemModel">
  <Files>
    <ProjectItemFile Source="Elements.xml" Target="ReusableWFFT" Type="ElementManifest" />
  </Files>
  <ExtensionData>
    <ExtensionDataItem Key="WorkflowType" Value="Site" />
  </ExtensionData>
</ProjectItem>

If you now save your file, then close your solution and afterwards reopen it again your workflow is now deployable as site workflow.
To check if this “hack” worked you should open the “Package Explorer” (“View” > “Other Windows” > “Package Explorer”), select your workflow within the Package Explorer and look at your Properties window. The last property is “Workflow Type”, it should say “Site”.

Workflow Type: Site

Workflow Type: Site

Allow content types to be grouped in views

Out of the box you’re not able to group your libraries by content type.
One way to achieve this is to activate the “Metadata Navigation and Filtering” feature under the site collection features.

Metadata_navigation_and_filtering

Metadata navigation and filtering feature

Afterwards go to “document library settings”, beneath “General Settings” click “Metadata navigation settings” and add the “Content Type” to the “Selected Hierarchy Fields”.

Configure Navigation Hierarchies

Configure Navigation Hierarchies

If you return to your library, you’ll find an extra navigation panel which allows you to navigate through your library by the fields earlier selected.

navigation

Metadata navigation

But another way to achieve content type grouping is to change your field schema xml of the content type field in your site collection. The following code example shows how to achieve this. Within the code example we change the sortable property on the field, out of the box the property is set to false but if we change is we are able to sort and group our views by content type.

private void ModifyContentTypeField(SPWeb web)
{
	SPFieldCollection fields = web.Fields;
 
	if (fields.Contains(SPBuiltInFieldId.ContentType))
	{
		SPField contentTypeField = fields[SPBuiltInFieldId.ContentType];
 
		if (contentTypeField != null)
		{
			string fieldSchemaXml = contentTypeField.SchemaXml;
 
			string replacedSchemaXml = Regex.Replace(fieldSchemaXml,
				"sortable=\"false\"", "Sortable=\"TRUE\"", RegexOptions.IgnoreCase);
 
			contentTypeField.SchemaXml = replacedSchemaXml;
			contentTypeField.Update(true);
		}
	}
}

You can add this to a feature to enable content type field grouping. If you now go to your view modification screen, you can now select content type from the Group By drop down box.

Group by content type

Group by content type

After selecting the content type field as group by field your view will look something like this.

View grouped content types

View grouped content types

SharePoint 2010 Developer Center

Microsoft has launched the  SharePoint 2010 (Beta) Developer Center website. The pages contains the following ten modules.

  • Module 1: Getting Started: Building Web Parts in SharePoint 2010
  • Module 2: What Developers Need to Know About SharePoint 2010
  • Module 3: Building Blocks for Web Part Development in SharePoint 2010
  • Module 4: Accessing SharePoint 2010 Data and Objects with Server-Side APIs
  • Module 5: Accessing SharePoint 2010 Data and Objects with Client-Side APIs
  • Module 6: Accessing External Data with Business Connectivity Services in SharePoint 2010
  • Module 7: Developing Business Processes with SharePoint 2010 Workflows
  • Module 8: Creating Silverlight User Interfaces for SharePoint 2010 Solutions
  • Module 9: Sandboxed Solutions for Web Parts in SharePoint 2010
  • Module 10: Creating Dialog Boxes and Ribbon Controls for SharePoint 2010

There’s also documentation on the SDK and a SharePoint Developer Evaluation guide.

WordPress Themes