BDC deployment error

When changing your identifier within your BDC model and deploying with Visual Studio afterwards, you might bump into an error looking something like the following.

Error occurred in deployment step 'Add Solution': Model file 'SendToMailModel\SendToMailModel.bdcm' has the following External Content Type activation errors:
TypeDescriptor with Name 'ID' (found in Parameter with Name 'returnParameter', Method with Name 'ReadList', Entity (External Content Type) with Name 'Contact' and Version '1.0.0.30' in Namespace 'SendToEmail.SendToMailModel') refers to an Identifier with Name 'ID' of Type 'System.Guid' which is supposed to exist on Entity with Name 'Contact' in Namespace SendToEmail.SendToMailModel'. This Identifier cannot be found.

I tried a lot of stuff trying to resolve the error
– investigating the model over and over again
– retracting the old model using Visual Studio
– uninstalling the dll from the GAC
– IIS reset, Timer Reset
– restarting VS

But unfortunately none of the above worked. Then I took a look at the BDC service application (Central Administration > Application Management > Manage service applications > Then click your BDC service), the “View External Content Types” page will be shown. What I first noticed was that my external content type wasn’t there, which I thought was a bit strange. Then I noticed the dropdown at the top of the page, which contains the different views of the page, I’ve never noticed it before and therefore never used it before.

BDC page views

BDC page views


After selecting “External systems” from the options in the dropdown, the view changed and I noticed my BDC model.
External systems view

External systems view


After changing to the “BDC Models” view of the page I also noticed my model was listed over there.

BDC models view

BDC models view

After deleting the model from both these pages I could deploy it again from Visual Studio.

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 Training Courses on Chanel 9

Chanel 9 has published 14 SharePoint 2010 training courses on their separate SharePoint 2010 Developer subsite. Some of the course subjects are the Developmer Roadmap, Workflows, Linq to SharePoint, Client object model. I haven’t seen them all, but there is enough material  to enjoy on a rainy day!

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