I had a request to make a whole library full of web part pages show the left navigation. These pages had been created and populated with web parts previously. Instead of editing the template on each of these pages manually, I decided to script it using PowerShell.
$w = get-spweb “http://sharepoint/sites/collection/subweb”
$f = $w.RootFolder.SubFolders["Pages"]
foreach ($p in $f.Files) {
$enc = [system.Text.Encoding]::ASCII
$b = $p.OpenBinary()
$str = $enc.GetString($b)
$new = $str -replace "<ContentTemplate>(.|\n)*</ContentTemplate>","<ContentTemplate></ContentTemplate>"
$new = $new -replace "<asp:Content.*PlaceHolderLeftNavBar.*/asp:Content>",""
$new = $new -replace "<asp:Content.*PlaceHolderLeftActions.*/asp:Content>",""
$new = $new -replace "^\?\?\?",""
$p.SaveBinary($enc.GetBytes($new))
}
The script opens each file in the “Pages” library that housed the web part pages and strips out the code that hides the left navigation.
No comments:
Post a Comment