3

I use multiple different webpart (ex : content editor, summary link webpart) which I would like to pushing on multiple pages.

So far, I’ve import/export the webparts. But if I have to modify one, I have to manually update all webpart that I’ve export. I would like to know if there’s any way of saving only 1 webpart and have all the other pages link that webpart into ?

Then If I have to make a modification on the webpart, I would only have to update 1 content editor for example, and the modification will be push automatically into the other pages with the same webpart.

Thank you Bobby

  • You can use powershell to automate this. Export WebPart and then import the WebPart again or just change the properties of the WebPart. – Remko Dec 16 '13 at 6:48
2

In general there is no way to make it such that editing a web part once is pushed into multiple pages, that requires some form of code.

BUT for the Content Editor web part you have the option of specifying a file with the content (see picture) instead of adding it to each web part. Then you can just modify that file and it's applied everywhere you use it.
enter image description here

Also note that if you want add an exported web part to a lot of pages in the same Site collection then you can make your job easier by uploading it to the Web Part Gallery (in site settings), then its available directly when you choose Add Web part instead of having to click: Add, Down arrow, Browse, Upload, Add.
enter image description here

  • I know this is an old post, but just to clarify so I make sure I have a correct understanding: Even if you upload the web part to the Gallery, pages that use the web part from the Gallery will NOT be updated when you update the web part? – kralco626 Sep 20 '17 at 17:40
  • No, the web part gallery is just a collection of web part configurations which can easily be copied into pages by adding them, but after the copy there is no connection back to the gallery – Per Jakobsen Sep 20 '17 at 18:31
1

You can use PowerShell for this

  • Export the modified WebPart
  • Import the exported WebPart xml file one or x times

First Export 1 or all WebParts on a page

$siteUrl = "<absolute url to the site>"
$pageUrl = "<site relative url to the page>"
$exportFolderPath = "<path for export webparts>"

$web = Get-SPWeb $siteUrl
$wpm = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

$wpm.WebParts | % {
 $wb = $_
 $wp.ExportMode="All";
 $exportPath = $exportFolderPath + "\" + $wp.Title + ".xml"
 $xwTmp = new-object System.Xml.XmlTextWriter($exportPath,$null);
 $xwTmp.Formatting = 1;#Indent
 $wpm.ExportWebPart($wp, $xwTmp);
 $xwTmp.Flush();
 $xwTmp.Close();
 }

To Update the existing WebPart You can use the following function

Function Update-WebPart{
[CmdletBinding()]
Param ( [Parameter(Mandatory=$true)][string] $Url,
        [parameter(Mandatory=$true)][string] $UrlPage,
        [parameter(Mandatory=$true)][string] $WebPartTitle,
        [parameter(Mandatory=$true)][string] $ImportPath
       )

        $web = Get-SPWeb $Url
        $page = $web.GetFile($UrlPage)

        if ($page.CheckOutType -ne "None")
        {
            $Page.UndoCheckOut()
        }

        Write-Host "Checkout page $UrlPage ..." -NoNewline
        $page.CheckOut()
        Write-Host -ForegroundColor Green '  - done.' 

        $webpartmanager=$web.GetLimitedWebPartManager($page.Url,  [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
        $webPart = $webpartmanager.WebParts | ? {$_.Title -match $WebPartTitle}
        if ($webPart -ne $null) {
            $webPartZoneId = $WebPart.ZoneID #"NavigationZone"
            $webPartZoneIndex = $webPart.ZoneIndex 
            $webPart | % { 
                       Write-Host "Delete WebPart $($_.Title) ..." -NoNewline
                       $webpartmanager.DeleteWebPart($_) 
                       Write-Host -ForegroundColor Green '  - done.' 
                    };
            Write-Host "Import new WebPart $WebPartTitle ..." -NoNewline
            [System.Xml.XmlTextReader]$xmlReader = new-object System.Xml.XmlTextReader($ImportPath);
            $Err = $null
            $webPart = $webpartmanager.ImportWebPart($xmlReader, [ref] $Err)
            $webpartmanager.AddWebPart($webPart, $webPartZoneID, $webPartZoneIndex)
            $webpartmanager.SaveChanges($webPart)
            Write-Host -ForegroundColor Green '  - done.'   

            Write-Host "CheckIn and Publish page $UrlPage ..." -NoNewline
            $page.checkIn("Update via PowerShell")
            $page.Publish("Update via PowerShell")
            Write-Host -ForegroundColor Green '  - done.'   
      }
    }

Now all you have to do is find the page or pages you want to update for example

$web = Get-SPWeb <url web>
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pagesListName = $pWeb.PagesListName
$urlWebWP = "<url to the page with the WebPart on it>"
$importPath = "<path and xml with the WebPart data>"

Update-WebPart -Url <url web> -UrlPage $urlWebWP -ImportPath $importPath -WebPartTitle "<Title of the WebPart you want to update>"
0

You can add the webpart to a page layout and use that page layout to whichever page the webpart is needed. Hence you can edit the webpart in the page layout and will be reflected in all other places.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.