How To Set Title to Required in Document Libraries   Leave a comment

SharePoint SearchThe SharePoint Search Service Crawler and Indexer uses the “Title” property first when content is indexed.  A new feature in SharePoint 2016 has the crawler picking up the first line or “header” of the document to help with indexing content.  By adding a Title to documents, SharePoint search will provide a better UX (User Experience) with SharePoint’s Search Results when users are searching for content.

By default the Title content in Document Libraries is not required, leaving many lazy users not filling out this field.  This could potentially give incorrect search results or results that are confusing.

You can easily set the Title to Required by going into the Document Content Type, but if there are many Libraries in Sites and Site Collections that could be cumbersome.

You can create a Feature (List Event Receiver) when a Library is provisioned to set the Title to required, and for existing libraries that can also be accomplished via PowerShell.

In this example, I have the Title property set during the provisioning process.

Public Class TitleRequired
Inherits SPListEventReceiver
”’
”’ A list was added.
”’

Public Overrides Sub ListAdded(properties As SPListEventProperties)
MyBase.ListAdded(properties)

Dim sSiteUrl As String = properties.Web.Site.Url
Dim sWebUrl As String = properties.Web.Url
Dim sLibraryName As String = properties.ListTitle
‘*************************************************************************************************
‘Note: Making the Title Column (Field) Required in a Document Library is Different from a
‘      Custom List.  The “Document” Content Type Associated with the List requires the Change.

‘      If Deactivating this Feature, you will need to Manually Set the Title Required proprety
‘      through the “Document Content Type” under “Allow Management of Content Types”.
‘*************************************************************************************************
Try
Using site As New SPSite(sSiteUrl)
Using web As SPWeb = site.OpenWeb()
                 Dim list As SPList = web.Lists.TryGetList(sLibraryName)
Dim contentType As SPContentType = list.ContentTypes(“Document”)
Dim titleField As SPField = list.Fields(“Title”)
Dim fieldLink As SPFieldLink = contentType.FieldLinks(titleField.Id)
web.AllowUnsafeUpdates = True
                fieldLink.Required = True
contentType.Update()
web.AllowUnsafeUpdates = False
            End Using
End Using
Catch ex As Exception
‘Throw a message in the ULS Logging
Microsoft.Office.Server.Diagnostics.PortalLog.LogString(“Exception Occurred ATI.SP.ER.SetTitleRequired: {0} || {1}”, ex.Message, ex.StackTrace)
End Try
End Sub
End Class

Posted June 29, 2017 by Bismarck in SharePoint 2013, SharePoint 2016

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: