Archive

Posts Tagged ‘Automation’

Add Links in SummaryLinksWebpart using PowerShell scripting

May 23rd, 2011 Comments off

More on the automation and adding data in other webparts. In previous post I talked about loading data in ContentEditorWebpart. Now look at SummaryLinkWebpart . Recently when i was working with SummaryLinkWebpart. I realised it is a bit different then other web parts to load links in summaryEditorWebpart. I looked for the internet but I couldn’t find any single example for SummaryLinksWebpart with power shell. So here is the example for others. I hope it will help some folks.

$webpart = new-object  $typeName
$webpartType = $webpart.GetType().ToString()

if($webpartType -eq “Microsoft.SharePoint.WebPartPages.ContentEditorWebPart”)
{
        if($values)
       {
               $keyValuePairs = $values.split(“,”)
               foreach ($keyValuePair in $keyValuePairs)
              {
                       $keyValueArray = $keyValuePair.Split(“|”)

                       [string]$propertyName = $keyValueArray[0].Trim()
                       [string]$propertyValue = $keyValueArray[1].Trim()

                       $sumLink = New-Object Microsoft.SharePoint.Publishing.SummaryLink $propertyName
                       $sumLink.LinkUrl = $propertyValue
                       $webpart.SummaryLinkValue.SummaryLinks.Add($sumLink)
                       $webpart.SummaryLinkValue = $webpart.SummaryLinkValue
              }
       }
}

Cheers

Load data in ContentEditorWebpart using PowerShell scripting

May 23rd, 2011 Comments off

If you are working on SharePoint content automation then powershell scripts are the most talked item. But sometime it is very difficult to find the right way to load data in web parts. For different web parts you have to treat differently. Here is the example to load data in ContentEditorWebpart.
I have a powershell function, where I’m passing some values including web part type and HtmlContent. HtmlContent is the text I want to set in ContentEditorWebpart.

$webpart = new-object  $typeName
$webpartType = $webpart.GetType().ToString()

if($webpartType -eq “Microsoft.SharePoint.WebPartPages.ContentEditorWebPart”)
{
        if($HtmlContent)
       {
              [string]$content = $HtmlContent.ToString()
              $docXml = New-Object System.Xml.XmlDocument
              $contentXml = $docXml.CreateElement(“Content”)
              $contentXml.set_InnerText($content)
              $docXml.AppendChild($contentXml)

              $webpart.Content = $contentXml
       }
}

I hope it will help.

Cheers