Change SummaryLinks Url using CSOM

Hi to all.

I'm creating a console application that will bulk replace one URL on 3000 identical SummaryLinks webpart hosted on the home page of 3000 different site collection, using CSOM.

Well...

I can get my webpart using LimitedWebPartManager, I can change some property (e.g. Title), but I can't access to the property SummaryLinkStore where the urls are stored.

The only way that I found is to delete (or close) the old webpart, create a new webpart based on the XML schema (manually exported and modified) and then add the new created webpart to the page.

Then...

Can anybody help me to find a way less invasive?

Thanks,

August 25th, 2015 6:05am

Hi,

We can use the .Net Client Object Model to achieve it, the following code snippet for your reference:

ClientContext context = new ClientContext("site url");

Microsoft.SharePoint.Client.File file = context.Web.GetFileByServerRelativeUrl("page url");
LimitedWebPartManager wpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
context.Load(wpm.WebParts, wps => wps.Include(wp => wp.WebPart.Title), wps => wps.Include(wp => wp.WebPart.Properties));

context.ExecuteQuery();

foreach (WebPartDefinition wpd in wpm.WebParts)
{
	WebPart wp = wpd.WebPart;
	if (wp.Title == "Summary Links") {
		wp.Properties["SummaryLinkStore"] = wp.Properties["SummaryLinkStore"].ToString().Replace("link name","new link name");
		wpd.SaveWebPartChanges();
		context.ExecuteQuery();
	}                            
}

Best Regards,

Dennis Guo

Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 11:38pm

Hi.

Thanks for your response.

I had thought of such a solution, very simple and linear, but the webpart class exposes the Properties property

:(

August 26th, 2015 2:46am

The referenced client assemblies in my case are 14.0.0.0 version.
Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 3:24am

Adding reference to the 16.0.0.0 assemblies, the properties property magically is appeared.

I'll try to use this new assembly on an old version of SharePoint (14).

I will update soon.

Thanks,

Sergio

August 26th, 2015 3:31am

Nothing to do.

Properties does not exist in SharePoint 2010.

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 3:44am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics