views:

109

answers:

1

I am working with a custom list I've built in SharePoint. I have a feature which has an event handler that kicks off when the feature is activated. That event handler calls (I can debug and watch it execute) the following function:

I'm intending that the function behaves as described here.

private void OrderFields(SPWeb web)
{
   // This works fine: I get the expected SPContentType object
   // There is only 1 SPContentType in ContentTypes
   SPContentType contentType = web.Lists[TASK_LIST_NAME].ContentTypes[0];

   contentType.FieldLinks.Reorder(new string[4]
   {
      "Field1",
      "Field2",
      "Field3",
      "Field4"
   });

   contentType.Update();
}

The function that calls OrderFields calls web.Update(); as well.

Unfortunately, the reorder call does not reorder my fields on my form. Am I missing something? Can anyone suggest any tricks I might try?

A: 

The problem was with my field names.

I had two lookups that I'd programmatically created earlier in the execution of the event handler. These lookups' internal names vary significantly from the "Field1" and "Field2" names I'd given them in the Name and StaticName parameters of my CAML definition.

Instead, the internal name seems to be composed of the Display Name, spaces replaced by "0020", and truncated to a length of 32 characters.

antik
That's why i always use a feature receiver to create lookup fields in code (since the normal CAML way you'd use creating fields on any other type besides lookup does not work, and using the UI is not an option when you are developing a huge site). This will happen to any field created though the UI with spaces in it, space replaced by _x0020_ and the max of 32 chars.
Colin
The feature receiver does create the lookup fields. It does so by reading XML out of a template file, setting the List property of the template to the source list's ID, and calling AddSchemaXML (I forget the function: it's not in front of me.)Perhaps there's a better way to create the field so that this doesn't occur?
antik