Archive for October, 2010

DisplayName of SPField is not set

October 28, 2010

Today I came across rather interesting “feature” in SharePoint 2010. I created a new LookupField programmatically and set the Title to a value. This value was however not used. The internal name was used in the display. The more i

So after some digging in .Net Reflector I came up with this. The setter of the Title property is implemented like this:

public void set_Title(string value)
	if (!this.Title.Equals(value, StringComparison.Ordinal))
		if (this.TitleResource != null)
			this.TitleResource.Value = value;
		if (CultureInfo.CurrentUICulture.LCID == this.Web.UICulture.LCID)
			this.SetFieldAttributeValue("DisplayName", value);
		if (this.TitleResource != null)
			this.SetFieldAttributeValue("DisplayName", this.TitleResource.GetValueForUICulture(this.Fields.Web.UICulture));

So the reason why this does not work is that I had a german site collection where and the server was english. In this case is the DiplayName not set. Cool
For comparison how it is implemented in SharePoint 2007:

public void set_Title(string value)
	this.SetFieldAttributeValue("DisplayName", value);

As you can see this could not have happened in the old version.
The solution is as follows. Switch the culture of the CurrentThread to the language of the SPWeb you want to work with.
Or do it through reflection

private static void SetFieldDisplayName(SPFieldLookup continuingProjectLookup, string displayName)
	Type baseType = continuingProjectLookup.GetType().BaseType;
	object obj = baseType.InvokeMember("SetFieldAttributeValue", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,	null, continuingProjectLookup, new object[] { "DisplayName", displayName });

Quick tips for using Powershell in SharePoint

October 12, 2010

Here are some helpful powershell commands that I am afraid that I will forget:

This powershell command will install PowerShell ISE. A Pretty tool for editing powershell scripts:

Import-Module ServerManager;Add-WindowsFeature PowerShell-ISE

This powershell command will enable SharePoint commands:

Add-PsSnapin Microsoft.SharePoint.PowerShell

This command opens a new SPSite and root SPWeb

$spsite = new-object Microsoft.SharePoint.SPSite(“http://localhost”)

$spweb = $spsite.OpenWeb()

Creating Loops in SharePoint Designer 2010 Workflows

October 7, 2010

By default SPD 2010 does not allow possible infinite loops to be added to a workflow. Here is the guide how you can do it:

  1. Open SPD 2010
  2. Add a new Workflow
  3. Add new IfElseActivity and fill in the conditions and the actions you want to loop through
  4. Save the workflow
  5. Go to Alle Files -> Workflows -> Your workflow name  folder and open  “your workflow name.xoml” file as xml.
  6. Locate the lines that look like this:

<IfElseActivity x:Name="ID411">

<IfElseBranchActivity x:Name="ID412">


<RuleConditionReference ConditionName="__Rule_ID412" />


And replace if with something like this:

<WhileActivity x:Name="ID411">


<RuleConditionReference ConditionName="__Rule_ID412" />



Keep in mind that you have to remove also the ending tag of the IfElseBranchActivity.  Keep also in mind that if you have multiple activities in the IfElseActivity taht you have to encapsulate these activities into one single SequenceActivity.

Now you can Publish your workflow back to SharePoint.

One drawback of this approach is that SPD does not support designing of a whileactivity in the worklow designer so you have to change the activities direct in the xoml file or you can replace the whileactivity again with ifelseactivity, do your changes and replace it again.

You have to also modify the web.config of the web app where you want to deploy your workflow because by default is the WhileActivity disabled. Locate following line

<authorizedType Assembly="System.Workflow.Activities, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="WhileActivity" Authorized="False" />

and set the “Authorized” attribute to True.