Online Training On SharePoint
                      
Showing posts with label PowerShell examples for Content Editor Web Parts. Show all posts
Showing posts with label PowerShell examples for Content Editor Web Parts. Show all posts

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
       }
}
Related Posts with Thumbnails