Monday, July 26, 2010

Can't persist changes to SummaryLinkWebPart

Apparently there is a bug when trying to programmatically change the links in the Summary Link Web Part.  I tried checking out the page first ( pageFile.CheckOut(); ).  I tried allowing unsafe updates (spWeb.AllowUnsafeUpdates = true; ) and I also tried updating, checkingIn, and publishing:

pageFile.Update();
pageFile.CheckIn("Updated by LinkUpdateTool");
pageFile.Publish("Updated by LinkUpdateTool");

None of which worked...

I was adding the links using:  << linkWP.SummaryLinkValue.SummaryLinks.Add(linkItem);  >> where linkItem is a SummaryLink object.

I looked up a bunch of code examples online but couldn't find anything else to try so I started playing around with ordering of the function calls to no avail. I then dug deep into a google search and found a single line of code which resolves an apparent bug in the API:

linkWP.SummaryLinkValue = linkWP.SummaryLinkValue;

Do this after you add your new links but before so save the WebPartManager.  Ie...

wpm.SaveChanges(linkWP);


Frustrating but so relieved I got it working!!

1 comment:

SaMolPP said...

hi,
thnx for the article.
how to remove the already existing links from this summary links?