Forum Discussion
Ole Bergtun
Dec 12, 2016Brass Contributor
Adding and Removing JSLink from view using CSOM
I'm trying to remove some JSLinks on views, but they will not go away... can someone help me spot where i go wrong?
File oFile = context.Web.GetFileByServerRelativeUrl(view.ServerRelativeUrl);
LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
context.Load(limitedWebPartManager.WebParts, wps => wps.Include(wp => wp.WebPart.Title));
context.ExecuteQuery();
var oWebPartDefinition = limitedWebPartManager.WebParts[0]; WebPart oWebPart = oWebPartDefinition.WebPart; var props = oWebPart.Properties; context.Load(limitedWebPartManager.WebParts, wps => wps.Include(wp => wp.WebPart.Title)); context.Load(props); context.ExecuteQuery(); oFile.CheckOut(); props["JSLink"] = linkToAnAlmostemptyJs; oWebPartDefinition.SaveWebPartChanges(); oFile.CheckIn("Added JSLink", CheckinType.MajorCheckIn); context.ExecuteQuery();
Best regards
Ole "Blinded" B.
- Kiril IlievBrass ContributorYou should take a look at the View's JSLink property instead of looking up in the web parts of the view.
just
view.JSLink = String.Empty
view.Update()
context.ExecuteQuery()