Share via


PageLayout.Title Property

Gets or sets the display title for this PageLayout object.

Namespace:  Microsoft.SharePoint.Publishing
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

Syntax

'Declaration
Public Property Title As String
    Get
    Set
'Usage
Dim instance As PageLayout
Dim value As String

value = instance.Title

instance.Title = value
public string Title { get; set; }

Property Value

Type: System.String
The title to be displayed for this PageLayout object.
Title can be set to an empty string. A a null reference (Nothing in Visual Basic) value is saved as an empty string.

Exceptions

Exception Condition
ArgumentNullException

.

UnauthorizedAccessException

The current user does not have sufficient permissions to perform this action.

Remarks

Title cannot exceed 255 characters. Any excess characters cause an SPException to be thrown when Update is called.

To save changes, the PageLayout.Update method must be called after setting this property.

The user must have edit permissions on the PageLayout object to set this value. The user must have view permissions on the PageLayout object to retrieve it initially and to get any of its property values.

If this property value is used in HTML that is rendered in a Web browser, you should encode the property value to avoid the possibility of scripting attacks.

Examples

Before compiling and running this sample, verify that the SPListItem object is a list item for a page layout that resides in the Master Page Gallery on the root Web.

This sample presumes that the Master Page Gallery that contains the SPListItem object requires content approval.

[C#]

using PageLayout = Microsoft.SharePoint.Publishing.PageLayout;
using SPListItem = Microsoft.SharePoint.SPListItem;
using SPFile = Microsoft.SharePoint.SPFile;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class PageLayoutCodeSamples
    {
        // This method sets some properties on a PageLayout object,
        // saves the new values, and publishes the PageLayout.
        public static void SetPageLayoutPropertiesAndApprove(SPListItem layoutListItem)
        {
            // TODO: Replace these variable values and input
            // parameters with your own values.
            // New PageLayout.Title value
            string newTitle = "your Title";
            // New PageLayout.Description value
            string newDescription = "your Description";
            // The comment to set when the layout is checked in,
            // published, and approved.
            string checkInComment = "your comments";
            // Validate the input parameters.
            if (null == layoutListItem)
            {
                throw new System.ArgumentNullException("layoutListItem");
            }

            // Get the PageLayout wrapper for the SPListItem
            // that is passed in.
            PageLayout pageLayout = new PageLayout(layoutListItem);

            // Check out the PageLayout if it is not checked out yet.
            if (pageLayout.ListItem.File.CheckOutStatus == 
              SPFile.SPCheckOutStatus.None)
            {
                pageLayout.ListItem.File.CheckOut();
            }

            // Set and save some properties on the PageLayout.
            pageLayout.Title = newTitle;
            pageLayout.Description = newDescription;
            pageLayout.Update();

            // Publish the PageLayout and Approve it so that the
            // updated values are available on the published Web site.
            pageLayout.ListItem.File.CheckIn(checkInComment);
            SPFile layoutFile = pageLayout.ListItem.File;
            layoutFile.Publish(checkInComment);
            layoutFile.Approve(checkInComment);

        }
    }
}

See Also

Reference

PageLayout Class

PageLayout Members

Microsoft.SharePoint.Publishing Namespace