Hi,
I have hundreds of webs which have document library on the home page. The request is to turn on the toolbar of the document library webpart on the main page. I fiddled a bit and found how to modify webpart only to find here Modifying the toolbar type of an XsltListViewWebpart programatically that Sharepoint doesn't provide any method or property in XsltListViewWebPart object to switch the toolbar values (WTF Microsoft? Seriously, user is able to do it in few clicks and developer has to use 2 pages of code?). Since I am more admin than developer I am doing this in Powershell and the code mentioned in the linked article is difficult for me to simply rewrite to Powershell. So I compared the webpart object when the toolbar is on and off and found only one difference in the XMLDefinition property. But when I modify the XML and save the changes and check it back I still can't see any change in the toolbar although the XMLDefinition property is literaly the same. What am I missing in the way I save it?
$site = Get-SPSite $siteurl
$web = Get-SPWeb $weburl
$page = $web.GetFile("default.aspx")
$page.CheckOut()
$wpm = $web.GetLimitedWebPartManager("default.aspx", [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$wpm.WebParts | ft title, description
$wp = $wpm.WebParts[4]
[xml]$x = $wp.XmlDefinition
$x.View.Toolbar.Type = 'Standard'
$x.View.Toolbar.SetAttribute('ShowAlways','TRUE')
$wp.XmlDefinition = $x.InnerXml
$wpm.SaveChanges($wp)
$page.CheckIn("")
$web.dispose()
$site.dispose()Here is the only difference of all attributes of the $wp when the toolbar is off and on:
<View Name="{9F78724E-174D-4192-B131-800DFED68454}" MobileView="TRUE" Type="HTML" Hidden="TRUE" DisplayName="" Url="/customers/apservissro/52001/default.aspx" Level="255" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/dlicon.png"><Query><OrderBy><FieldRef Name="FileLeafRef"/></OrderBy></Query><ViewFields><FieldRef Name="DocIcon"/><FieldRef Name="LinkFilename"/><FieldRef Name="Modified"/><Field Ref Name="Editor"/></ViewFields><RowLimit Paged="TRUE">30</RowLimit><Toolbar Type= "Freeform"/></View><View Name="{9F78724E-174D-4192-B131-800DFED68454}" MobileView="TRUE" Type="HTML" Hidden="TRUE" DisplayName="" Url="/customers/apservissro/52001/default.aspx" Level="255" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/dlicon.png"><Query><OrderBy><FieldRef Name="FileLeafRef"/></OrderBy></Query><ViewFields><FieldRef Name="DocIcon"/><FieldRef Name="LinkFilename"/><FieldRef Name="Modified"/><FieldRef Name="Editor"/></ViewFields><RowLimit Paged="TRUE">30</RowLimit><Toolbar Type="Standard" ShowAlways="TRUE"/></View>