Wednesday, May 5, 2010

SharePoint Delete the Title field from Document or Picture Library

“Title” column of a Document/Picture library through object model can’t be deleted and gives an error. This is because the “CanBeDeleted” property of that field has the value “false”. The column will not be deleted even if “AllowDelete” property is set to “true”, after this it gives another error saying that “sealed property can’t be deleted”. To delete the column, schema.xml of “Document/Picture Library” needs to be customized, which can be found at the following location.
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\Document or Picture Library\DocLib or PicLib
1. Open the schema.xml from the above location
2. Locate the “Title” field and change the sealed attribute value as Sealed="TRUE" to the tag.
Sealed="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Title" ColName="nvarchar7"/>

Code for deleting the Title Field:-
using(SPSite siteCollection = new SPSite ("Web Application"))
{
   using(SPWeb parentWeb = siteCollection.OpenWeb())
   {
      SPList oList = parentWeb.Lists["Document/Picture Library Name"];
      SPField oField = oList.Fields["Title"]; //Column name
      oField.AllowDeletion = true;
      oField.Delete();
   }
}

No comments:

Post a Comment