1

I'm using Sharepoint 2010. I've looked and tested several methods to try to do what is describe in the title of this post, but none of them are working.

In the best case, the so called attribute is modified during the script execution but modifications are not saved and my Webpart stays in the same state.

Here is my current attempt. It is not working even if there is no error thrown.

$web = get-spweb "http://whatever";   
$list = $web.lists["myList"];
$list2 = $web.lists["my2ndList"];
$wpPage = $list.RootFolder.files | ?{$_.url -match "dispform.aspx"};
$webpartManager = $wpPage.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared);
$webpart = $webpartManager.webparts[$index]; # index of the webpart on the page. It's correct because I can see all the properties that I want.
$viewID = $webpart.ViewGuid.ToString();
$view = $list2.Views | ?{$_.ID -eq $viewID};
$setToolbarTypeParameterTypes = [uint32];
$setToolbarTypeMethod = $view.GetType().GetMethod("SetToolbarType", [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic, $null, $setToolbarTypeParameterTypes, $null);
$setToolbarParameters = [uint32] 1; # this is suppose to set the tooblar to "None"...
$view.Update();     
$wpPage.Update();
$web.dispose()  
0

I vaguely remember having this issue and found this bit of code from a 2010 project I did years ago. Hopefully this will help:

$view = $list2.views | ?{$_.id -eq "some_guid"};
$viewType = $view.GetType()
$bindingFlags = [Reflection.BindingFlags]::InvokeMethod -bor [Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Instance
$obj = "Toolbar"
$toolbarNode = [System.Xml.XmlNode]$viewType.InvokeMember("GetNodeFromXmlDom", [System.Reflection.BindingFlags]$bindingFlags, $null, $view, [System.Object]$obj)
$toolbarNode.Attributes["Type"].Value = "None"
  • I have the error message Unable to index into an object of type System.Xml.XmlAttributeCollection at the very last line. – ameliapond Jan 27 '17 at 19:02
  • Are you sure it's a xslt web part and not a list view web part? What is returned from running $toolbarNode.Attributes? – Bunzab Jan 30 '17 at 14:09
0

Hi guys I found a way to acheive this. Actualy this parameter only takes strongly xml typed value. So it just dont work with usual text. Enjoy :)

$culture = new-object System.Globalization.CultureInfo("fr-FR"); // You should put the right value here. I'm using french version of SP2010 so it's fr-FR for me.
$wpView = $list.Views | ?{$_.ID -eq $wpID};
$wpView.GetType().InvokeMember("EnsureFullBlownXmlDocument", [Reflection.BindingFlags] "NonPublic, Instance, InvokeMethod", $null, $wpView, $null, $culture);    
$nodeProp = $wpView.GetType().GetProperty("Node", [Reflection.BindingFlags] "NonPublic, Instance");
[System.XML.XMLNode]$node = $nodeProp.GetValue($wpView, $null);
[System.XML.XMLNode]$toolbar = $node.SelectSingleNode("Toolbar");
$toolbar.Attributes.ItemOf(0).Value = "None";
$wpView.Update();
$webpartPage.Update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.