Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to programatically update the title of some webparts. To do this, I am getting all the pages from the site, getting the webparts for each page, and first print out the current title, change it and then print it out again to verify the title was correctly changed. Nevertheless, if I afterwards check, I still see the old title for the webparts... What am I missing?

The code is as follows:

... getting the pages for the site...
SPFile ofile = page.File;

SPLimitedWebPartManager wpColl = ofile.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.User);
int cont = wpColl.WebParts.Count;

for (int i = 0; i < cont; i++)
{
    System.Web.UI.WebControls.WebParts.WebPart wp1 = wpColl.WebParts[i];
Console.WriteLine("        - Title : " + wp1.Title);

wp1.Title = "test" + i;

ofile.Update();
Console.WriteLine("        - New title: " + wp1.Title);

page.Update();
site.Update();                             
}

Thanks for any tips! :)

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

You are missing:

  wpColl.SaveChanges(wp1);
share|improve this answer
    
Absolutely, it worked! :-D –  Aidenn Jun 1 '12 at 6:31
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.