Sep 15 2016 11:08 PM
Is there a way to change toolbar type on ListView WebPart via CSOM?
It doesn't seem to work
Sep 18 2016 11:14 PM
Sep 18 2016 11:56 PM
Hi Paul,
I have tried that. The thing is that so called 'Show Toolbar' mode, adds another attribute to toolbar node.
It looks like Toolbar Type='Standard' ShowAlways='TRUE'.
Any change one tries to make, doesn't effect toolbar behaviour.
Event tried to change XmlDefinition directly and update the view. Nothing. 😞
Funny thing however, if you do that using Sharepoint designer, and add that attr directly it works.
In addition I see that in PnP provisioning framework, toolbar is removed from view definition.
Object List Instance ExtractViews Method :
// Toolbar is not supported
var toolbarElement = schemaElement.Descendants("Toolbar").FirstOrDefault();
if (toolbarElement != null)
{
toolbarElement.Remove();
}
Sep 19 2016 04:49 AM
Hi Alen,
that is strange you can not update the xml def but the view should be possible did it in my code as well.
Maybe it changed with the latest csom or PNP.
KR,
Paul
Sep 19 2016 05:15 AM
Hi Paul,
It works now. I managed to change toolbar type.
Actually it was the problem in XsltWebPartPostProcessor Process method.
It invokes UpdateHiddenView(xsltHiddenView, listView.ListViewXml);
I have added overload with changed listviewSchemaXml as parameter, and update now works like a charm.
Thanks for help.
Alen
Sep 19 2016 11:08 PM
Cool so my post helped you a bit in the right direction 😉
May 11 2017 07:29 PM
Mar 13 2021 12:10 AM - edited Mar 13 2021 12:12 AM
Its not that complicated like its showcased in many forum. Below is the script which works for me in SPO. Need to update ListViewXml property and string needs to XMl Strongly typed.
$listView = $list.Views.GetById($webpart.ID);
$ctx.Load($listView);
$ctx.ExecuteQuery();
#Update toolbar to None
$listView.ListViewXml = ($listView.ListViewXml).Replace('<Toolbar Type="Standard"/>','<Toolbar Type="None"/>');
$viewSchemaElement = [System.Xml.Linq.XElement]::Parse($listView.ListViewXml) #to update ListviewXMl , string needs to XMl strongly typed
$xml =[String]::Concat($viewSchemaElement.Elements())
$listView.ListViewXml =$xml;
$listView.Update();
$listView.Context.ExecuteQuery();