0

I have migrated from SP 2007 to SP 2010 and have some error webparts with content I need to keep. I would like to move the content into a OOTB Content Editor Web Part as a part of my SharePoint 2007 - 2010 migration.

1 Answer 1

0

After doing the DB attach I was able to take the content that survived (but throws error) and migrate it to a CEWP like this:

    $ThisTownIsNotBigEnoughForTheTwoOfUs = ‘http://dev-NotMyCompany’

    ######################## Load Snapin ###################### 
    $snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
    if ($snapin -eq $null)
    {  
        Add-PSSnapin "Microsoft.SharePoint.Powershell"
    }
    ######################## End Snapin ########################

    function RADSwap([string]$Url)
    {
        write-host "Processing $Url"

        $ParseMe = $Url
        Do 
        {
            $ParseMe = $ParseMe.Remove($ParseMe.LastIndexOf("/"))
            $web = get-spweb $ParseMe -ErrorAction SilentlyContinue
        } while ($web -eq $null)

        $page = $web.GetFile($Url)

        write-host "  Checking out $page from $web"

        if ($page.CheckOutType -ne "None")
        {
            try
            {
                $page.UndoCheckOut()
            }
            catch
            {
                $ManualList = $ManualList + $Url
            }
        }

        $page.CheckOut();

        $wpm = $page.GetLimitedWebPartManager("shared");
        $WebParts = $wpm.WebParts;

        write-host "  Iterating through Web Parts"
        for ($i = $webParts.Count -1 ; $i -ge 0; $i--)
        {  
        $webPart = $webParts[$i]
            if ($WebPart.RepresentedWebPartType.Name -eq "RadEditorWebPart")
            {
                write-host '    Found RadEditorWebPart. Title:' $webPart.Title '; Zone:' $webPart.ZoneID '; Index:' $webPart.ZoneIndex
                $BlackHat = $webpart
                $Lair = $BlackHat.GetTextForSourceColumn();
                $SixShooter = [xml]$Lair.Replace("BADMARKUP","").trim()
                $HandCuffs = [xml]($SixShooter).BadMarkupData.DesignText
                $DamselInDistress = ($HandCuffs).WebPart.Text.("#text");

                $WhiteHat = new-object Microsoft.SharePoint.WebPartPages.ContentEditorWebPart
                    $WhiteHat.ChromeType = $BlackHat.ChromeType
                    $WhiteHat.Title = ($HandCuffs).WebPart.Title
                    $WhiteHat.ChromeType = "None" 

                $Horse = New-Object System.Xml.XmlDocument
                $Saddle = $Horse.CreateElement("Content");
                $Saddle.set_InnerText($DamselInDistress);
                $Horse.AppendChild($Saddle);

                $WhiteHat.Content = $Saddle;

                write-host '      Adding new Web Part'
                $wpm.AddWebPart($WhiteHat, $BlackHat.ZoneID, $BlackHat.ZoneIndex);

                if ($BlackHat.IsClosed)
                {
                    $wpm.CloseWebPart($wpm.webparts[($wpm.webparts.count-1)])
                    $wpm.SaveChanges($wpm.webparts[($wpm.webparts.count-1)])
                }

                write-host '      Deleting old Web Part'
                $wpm.DeleteWebPart($BlackHat);
            }
        }


                write-host '      Checking in'
        $page.CheckIn("Script: Updating the page to replace the TelerikRADEditor with OOTB CEWP.",[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);

        if ($page.Item.ListItems.List.EnableMinorVersions)
        {
                write-host '      Publishing file'
        $page.Publish("Script: Publishing the updated page to replace the TelerikRADEditor with OOTB CEWP.");
        }

        if ($page.Item.ListItems.List.EnableModeration)
        {
                write-host '      Approving'
            $page.Approve("Script: Approving the page which has a replaced TelerikRADEditor with OOTB CEWP.");
        }

    }


    function enumerateWebParts($Url2) {
    #### Shout out to Ghazwan Khairi for this function ####
    #### http://sharepointquester.com/2012/09/11/list-all-web-parts-in-a-sharepoint-2010-site-collection-using-windows-powershell/ ####
        $site = new-object Microsoft.SharePoint.SPSite $Url2    
        foreach($web in $site.AllWebs) {
            if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)) {
                $pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
                $pages = $pWeb.PagesList
                foreach ($item in $pages.Items) {
                    $fileUrl = $webUrl + “/” + $item.File.Url
                    $manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
                    $wps = $manager.webparts
                    $wps | where-object {$_.RepresentedWebPartType.Name -eq "RadEditorWebPart"} | select-object @{Expression={$pWeb.Url + $fileUrl};Label=”URL”}

                }
            }
            else {
                $pages = $null
                $pages = $web.Lists["Site Pages"]
                    if ($pages) {
                        foreach ($item in $pages.Items) {
                            $fileUrl = $webUrl + “/” + $item.File.Url
                            $manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
                            $wps = $manager.webparts
                            $wps | where-object {$_.RepresentedWebPartType.Name -eq "RadEditorWebPart"} | select-object @{Expression={$pWeb.Url + $fileUrl};Label=”URL”}
                    }
                }
                else {
                }
            }        Write-Host “… completed inventorying” $web
        }
    }
    $row = enumerateWebParts($ThisTownIsNotBigEnoughForTheTwoOfUs)
    $row | %{$_.URL.ToString()} | select-object -Unique | %{RADSwap($_)}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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