Online Training On SharePoint
                      

Tuesday, 13 December 2011

Updating Content Editor Web Parts using Powershell

I was working on a project where we need to update quite a few Content Editor web parts in a SharePoint 2010 applications. This task was taking longer to do manually but can be done quickly by using a Powershell script. Here is the Powershell which you can use to load data in Content Editor Web Parts:

$CEWebPart = new-object  $typeName
$CEWebPartType = $CEWebPart.GetType().ToString()

if($CEWebPartType -eq “Microsoft.SharePoint.WebPartPages.ContentEditorWebPart”)
{
        if($WebPartContent)
# This content would be updated in the Web Part
       {
              [string]$content = $WebPartContent.ToString()
              $oXml = New-Object System.Xml.XmlDocument
              $WebPartXml = $docXml.CreateElement(“Content”)
              $WebPartXml.set_InnerText($content)
              $oXml.AppendChild($WebPartXml)
              $CEWebPart.Content = $WebPartXml
       }
}

1 comment:

Cathy Walker said...
This comment has been removed by the author.
Related Posts with Thumbnails