SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to do a bulk page rename (NB. the file name e.g. default.aspx, not the displayed title)

foreach (PublishingPage page in pweb.GetPublishingPages())
    page.Name = GetNewNamingConventionForPage(page.Name); //error, it's read only

What gives? I can rename it manually in the pages library.

share|improve this question
up vote 1 down vote accepted

You need to set the "FileLeafRef" field of the underlying SPListItem for the publishing page. You need to first check out the file (or create it and then Update it for new sites), update the .ListItem["FileLeafRef"] property and then check it back in and publish it.

This code is to create a new publishing page and then change the file name. You have to run the .Update on the PublishingPage before setting the FileLeafRef otherwise you get an "object does not exist" error.

if (PublishingWeb.IsPublishingWeb(curWeb))
    PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(curWeb);
    PublishingPage pubPage = pubWeb.AddPublishingPage();

    pubPage.Title = "My New Page Title";

    pubPage.ListItem["FileLeafRef"] = "default";  //.aspx is added automatically
    pubPage.ListItem.SystemUpdate();  //SystemUpdate doesn't update the modified fields

Update: BaseName changed to FileLeafRef, BaseName is readonly and we can't update this field.

share|improve this answer
i've renamed them all by hand now, but i'll trust you that this works ;) – Anonymous Apr 30 '10 at 13:16

Its beacuse PublishingPage.Name is a read-only property.

You could try:


I have not tested this so do not know if this will do exactly what you need, but you definitely cannot set using the Name property.

share|improve this answer
this sounds right.. also note the difference between the name (filename) and the title.. – Anonymous Mar 26 '10 at 21:43
doesn't work either. – Anonymous Apr 26 '10 at 12:04
var url = oldUrl.Replace(oldFileName, newFileName);
share|improve this answer
It would be great if you could add a little more explanation to your answer than just the code, otherwise it gets automatically flagged. Thanks. – SPDoctor Feb 10 '12 at 14:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.