Complete XslLinks path in *.webpart file

18/07/2012 23:28

 

#input parameters
$siteUrl="https://localhost/sites/banner"
$srcPath="c:\temp\NewsOverview.webpart"#BannerWebPart.webpart"
 
 
$file=[xml](get-content $srcPath)
 
#Get nodes with Xsl Link settings (not error if node doesn't exist)
$main=$file.webparts.webpart.data.properties.property|where {$_.name -match "MainXslLink"}
$header=$file.webparts.webpart.data.properties.property|where {$_.name -match "HeaderXslLink"}
$item=$file.webparts.webpart.data.properties.property|where {$_.name -match "ItemXslLink"}
 
$links=@($main, $header, $item)
 
 
function GetSiteFromUrl(
    [string]$url
)
{
$first=$url.IndexOf('/')
$short=$url.substring($first+2,$url.length-$first-2)
$index=$short.IndexOf('/')
$site=$short.substring($index+1, $short.length-$index-1)
return $site
}
 
$prefix=GetSiteFromUrl -url $siteUrl
$prefix="/"+ $prefix
$prefix
 
foreach($link in $links)
{
 
$text=$link."#text"
#write-host "Vynatok z linku:" $text.substring(0, $prefix.length)
 
#Check if site url is already added to links, if not, add it
if($text.substring(0, $prefix.length) -ne $prefix)
{
    $text=$prefix + $text
    $text
    $link.set_InnerText($text)
}
 
}
$file.Save($srcPath)