Category: SharePoint 2010

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

WordPress Themes