Search code examples
sharepoint-2007

Programmatically added SummaryLinkWebPart doesn't display Links


I am using below code to Add SummaryLinkWebPart to a Page and also adding few links to that wehbpart. I can see the webpart now on the page but it doesn't have any links inside it. Does anyone know what is wrong with the code?

var wpm = web.GetLimitedWebPartManager("Pages/default.aspx", PersonalizationScope.Shared);

SummaryLinkWebPart slwp = new SummaryLinkWebPart();
    for (int counter = 0; counter < list.ItemCount; counter++)
    {
         urlField = list.Items[counter]["URL"].ToString().Split(',');

         SummaryLink link = new SummaryLink(urlField[1].Trim());
         slwp.SummaryLinkValue.SummaryLinks.Add(link);
         slwp.SummaryLinkValue.SummaryLinks[counter].OpenInNewWindow = true;
         slwp.SummaryLinkValue.SummaryLinks[counter].LinkUrl = urlField[0].Trim();
         slwp.SummaryLinkValue.SummaryLinks[counter].Description = urlField[1];
         slwp.Style = "Image on left";
         Console.WriteLine(link.LinkUrl + link.Title);
    }

    wpm.AddWebPart(slwp, lvwp.ZoneID, slwp.ZoneIndex + 1);

Solution

  • Hmm this seems to be the hack but the only thing that solves this issue is reassigning the SummaryLinkValue Property back again its value.

    slwp.SummaryLinkValue = slwp.SummaryLinkValue;