Archive

Archive for May, 2011

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

Hide the ‘Pages’ library in SharePoint breadcrumb

May 11th, 2011 Comments off

SharePoint breadcrumb is a nice feature to have on the pages. But it doesn’t fit very easily in usual scenario. If you also want to get rid of ‘Pages’ library link in the breadcrumb of a publishing site then see the below instructions.

Normal breadcrumb

My Portal -> Pages -> Test Page1

Updated breadcrumb

My Portal -> Test Page1

Then change the breadcrump source provide to CurrentNavSiteMapProviderNoEncode.  You have to change this in SiteMapPath tag like this…..

<asp:SiteMapPath SiteMapProvider=”CurrentNavSiteMapProviderNoEncode” id=”ContentMap” SkipLinkText=”" NodeStyle-CssClass=“ms-sitemapdirectional runat=“server”/>

 Now when we use CurrentNavSiteMapProviderNoEncode, we have to make sure that ‘Show Pages’ is true for current navigation. Even if you don’t want to display pages on the left navigation you have to enable it. Then you can hide your pages one by one from the navigation settings.

Cheers