Question

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()  
Était-ce utile?

La solution 2

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();

Autres conseils

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"
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top