Programmatically set the title of a SharePoint page?

I need to set the page title (Page Title) of a SharePoint page in code. I already tested

this.Page.Title = "My Page Title"; 

But this does not change the name when loading the page. Can anyone offer any advice on how to do this?

Thank you MagicAndi

+6
api sharepoint moss sharepoint-2007
source share
2 answers

If you want to change the name of the page from the web page on the page, for example, you can use this:

 private void ChangeTitle(string newTitle) { SPListItem item = SPContext.Current.ListItem; if (item != null) { item[SPBuiltInFieldId.Title] = newTitle; item.SystemUpdate(false); } } 

This will only work for a page in the page library, because there is no linked list on the default.aspx page in the root directory of your site. Also, do not forget to refresh the page after changing the name.

SystemUpdate ensures that the β€œmodified / changed” information is not updated and the version number does not increase. If you want this information to be updated, replace it with item.Update ();

+6
source share

This Michael Becker blog post provides a way to change the title of a SharePoint page using the following code:

 ContentPlaceHolder contentPlaceHolder = (ContentPlaceHolder) Page.Master.FindControl("PlaceHolderPageTitle"); contentPlaceHolder.Controls.Clear(); LiteralControl literalControl = new LiteralControl(); literalControl.Text = "My Page Title"; contentPlaceHolder.Controls.Add(literalControl); 
+7
source share

All Articles