2007-07-02

Missing Created field in Pages, Documents and other lists after CMS content has been moved between site collections

I do not know if the reason for why the Created column becomes missing (is set to hidden in the list) after moving some migrated CMS 2002 content into a regular Pages publishing list, really is related to CMS and content migration, but ... I really can't understand why SharePoint has done this to me/us/the project, but a solution must be found. At the moment we are unable to display the Created column in the lists view, set the sorting order based on the Created column, and so on.

Using the SharePoint Manager 2007 tool written by Carsten Keutman I was able to discover the fact that
  1. Hidden = True - obviously!
  2. The CanToggleHidden = False (bollocks!) - that gave me the headache - because if it was set to True I could have used Keutman's tool there and then to fix the bug (!?!?). CanToggleHidden can't be changed - it's an internal property - or ...??

But Colin Byrne, Flexnet, had the answer : Set the internal CanToggleHidden property via reflection

string id=list.Fields.Add("NewField5",SPFieldType.Boolean,false);

SPField spfield=(SPField)list.Fields.GetField(id);

Type type = spfield.GetType();

MethodInfo mi= type.GetMethod("SetFieldBoolValue",BindingFlags.NonPublic BindingFlags.Instance);

mi.Invoke(spfield,new object[]{"CanToggleHidden", true});

spfield.Hidden=true;

spfield.Update();

Haven't tried it myself yet, but comments on the blog confirmed that it would work.

No comments: