Customization of Title field in Picture Library


How we can make Title field as required in Picture libraries:-

A picture library is created based upon a base template “PictureLibrary”.

clip_image001[4]

By default, the title field doesn’t contains any validation. If you want to make it as required one, you need to customize the schema.xml of “PictureLibrary”, you can see the schema.xml in the following location.

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\PictureLibrary\PicLib

1. Open the schema.xml from the following location

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\PictureLibrary\PicLib

2. Locate the “Title” field and add this attribute - Required="TRUE" to the <Field> tag.

<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" ShowInNewForm="FALSE" ShowInFileDlg="FALSE"

DisplayName="$Resources:core,Title;" Sealed="FALSE" Required="TRUE" SourceID="https://schemas.microsoft.com/sharepoint/v3" StaticName="Title">

3. Now install and activate the feature and create a picture library and try to add a new picture without giving the title, then you can see validation fires.

clip_image002[6]


How we can delete the Title field from the Picture Library :-

Once, I have tried to delete the “Title” column of a picture library though object model and got an error and found that we can’t delete that particular field because the “CanBeDeleted” property of that field has the value “false”. Then, I have tried to delete the field by making the “AllowDelete” property as “true”, then I got another error saying that “we can’t delete any sealed property”, then I checked the XML schema and found that “Title” field is sealed.

Then I have followed the same steps that I did for modifying the Title field before (for adding the validation). I have located the schema.xml and modified the Title field by making the Sealed property as “True”, and after that I was able to delete the Title field successfully.

<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" ShowInNewForm="FALSE" ShowInFileDlg="FALSE" DisplayName="Title" Sealed="TRUE" SourceID="https://schemas.microsoft.com/sharepoint/v3" StaticName="Title" ColName="nvarchar7"/>

Code for deleting the Title Field:-

SPSite siteCollection = new SPSite ("https://<SiteName>/");

SPWeb parentWeb = siteCollection.OpenWeb();

SPList oList = parentWeb.Lists["MyPictureLibrary"];

SPField oField = oList.Fields["Title"];

oField.AllowDeletion = true;

oField.Delete();

NB : Direct modification of OOB feature files are not a recommend approach, So, you can copy the PictureLibrary feature folder and customize it and install that custom feature to your site collection. I have provided the above information for giving an idea about the customization.