Out of Box Columns are a Pain in the Ass

by dave Wed, September 28 2011 00:56

Before I begin my rant, let me qualify this by saying this only applies if you are building an *application* on top of SharePoint.  If you’re just using it largely out of the box for simple collaboration and content storage then this post likely doesn’t apply to you.  If you’re pushing things a bit and using SharePoint as an application framework, read on…

Folders are a nice logical organization structure.  Sure, lots of people bemoan the use of folders, preferring a metadata-based approach, and I’m not going to argue that point here.  Suffice it to say that sometimes, perhaps especially when you’re building an application on the SharePoint platform, folders make sense.  So now let’s discuss why the out of the box columns are a PITA.

Take for example, the Name column on the Folder content type.  If you’re following along at home, it has an InnerFieldName of FileLeafRef.  For whatever reason, you can’t delete this field (OK, I actually get this one…it’s used all over the place in SharePoint and deleting it would break things).  But the problem is, you can’t easily HIDE this column, either.  The CanToggleHidden property for this field is false and its read-only so we can’t change it.  This means that the code myField.Hidden = true throws an error.

OK, so let’s not try to set the Hidden property, but let’s just remove it from the various places it shows up.  There’s nothing that stops us from setting the ShowInXXXForms properties (ShowInDisplayForm, ShowInNewForm, ShowInEditForm) to false.  That will achieve the same effect as setting Hidden to true, right?

Unfortunately, no.  It appears that the default forms do not honor these properties, at least not for the FileLeafRef/Name field.  Here’s what I get after setting the ShowInXXXForms properties to false for FileLeafRef:

image

The field still shows up.  Sad smile

Interestingly, if I run the same code, but have a custom form configured to display the content type, I get the results I expected:

image

Luckily, I am using custom forms for this application so I’ll get the results I wanted. 

[EDIT: Make sure that you set the ShowInXXXForm properties AFTER the last content type is added to the list or else the fields will still show up]

Dave

Tags: ,

Development | SharePoint 2010