Monday, May 30, 2011

SharePoint 2010 Fields or Columns Naming Problem

I was hammered by a bug found by our client. They were trying to reorder fields of a custom list and for some reason SharePoint threw the following error.


After hours and hours of investigation I finally found out what the problem is.
There were spaces in the name property of the fields. In theory SharePoint should have converted the spaces into “_x0020_” and everything should be okay. However reordering fields of this custom list produces the error above.

SharePoint does not like:
  <Field ID="{176C37CB-99E2-4730-8B61-C994151094B8}" Name="Field 1 With Spaces" StaticName="Field1WithSpaces" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="FESA.SPS2010.Internet" DisplayName="Field 1 With Spaces" Type="Note" NumLines="10" RichText="TRUE" Description="Field 1 With Spaces" RichTextMode="FullHtml"></Field>
  <Field ID="{DC7451BC-BF4C-43F1-B443-E297190C008A}" Name="Field 2 With Spaces" StaticName="Field2WithSpaces" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="FESA.SPS2010.Internet" DisplayName="Field 2 With Spaces" Type="Note" NumLines="10" Description="Field 2 With Spaces" RichText="TRUE" RichTextMode="FullHtml" />

But it likes:
  <Field ID="{176C37CB-99E2-4730-8B61-C994151094B8}" Name="Field1WithoutSpaces" StaticName="Field1WithoutSpaces" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="FESA.SPS2010.Internet" DisplayName="Field 1 Without Spaces" Type="Note" NumLines="10" RichText="TRUE" Description="Field 1 Without Spaces" RichTextMode="FullHtml"></Field>
  <Field ID="{DC7451BC-BF4C-43F1-B443-E297190C008A}" Name="Field2WithoutSpaces" StaticName="Field2WithoutSpaces" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="FESA.SPS2010.Internet" DisplayName="Field 2 Without Spaces" Type="Note" NumLines="10" Description="Field 2 Without Spaces" RichText="TRUE" RichTextMode="FullHtml" />

So the lesson is not to have any spaces (or any invalid characters) in the name of the Fields.

Have a great day everyone.

No comments:

Post a Comment