Sunday 22 November 2020

How to upload the SharePoint 2010 site template in SharePoint Online

Moving site templates between different versions, such as SharePoint 2010 to SharePoint 2013, is not supported. Moving between SharePoint Servers 2013, 2016, and 2019 should work. 

You will get below error when you try to upload/activate the SharePoint 2010 template/solution in SharePoint Online version.

In order to export the site with content, navigate to Site Settings in SharePoint and click “Save site as a template”. 

Remember to check off "Include Content" before hitting OK to be sure you include the content. If you have a lot of content and want to do a dry-run first, then you can skip including the content the first time around.

Note: If you don't have the ability to save the site as template then below reasons why you can not save site as template.
a. You have publishing feature enabled
b. Custom script is not allowed in tenant level(applies to SPO)
c. You have group connected site or communication site.

To allow custom scripts, you need to run the below script using SharePoint Online Management Shell:
$AdminCenterURL = "https://tenant-admin.sharepoint.com/"
$SiteURL="https://tenant.sharepoint.com/Sites/url"

#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)

#Disable DenyAddAndCustomizePages Flag
Set-SPOSite $SiteURL -DenyAddAndCustomizePages 0

It can take up to 24 hours before the setting is enabled. After this you should be able to save as a template. or you can directly access this using below URL:

http://tenant.sharepoint.com/sites/url/_layouts/_savetmpl.aspx

Once you save the site as template, you can download it from the solution gallery..

Click the name of the package to save it on your local computer.

Now we have the downloaded solution package which is a 2010 version and it is not compatible as a 2013 site template in SharePoint Online.However we make the package compatible with SharePoint Online by changing the UI Version from the Onet.xml file by extracting the solution file.
  1. Change the extension of the solution package from WSP to CAB and extract is using 7-zip or winrar.
  2. Open the Onet.xml file into text editor from WebTemplate folder.
  3. The first row of he file will look something like below.
<Project Title="ProjectTemplate111120" Revision="0" UIVersion="4" EnableMinimalDownload="FALSE" SiteLogoUrl="" SiteLogoDescription="" xmlns="http://schemas.microsoft.com/sharepoint/">

Change the UIVersion number 4 to 15.

<Project Title="ProjectTemplate111120" Revision="0" UIVersion="15" EnableMinimalDownload="FALSE"  SiteLogoUrl="" SiteLogoDescription="" xmlns="http://schemas.microsoft.com/sharepoint/">

Now we are good to packing up the previously extracted to a new WSP file. You can use CabMaker, to create the WSP file.
Download the CabMaker from here

Upload the solution to SharePoint Online:

Navigate to the site collection in SharePoint Online you want to provision the site, and once again navigate to the Solution Gallery from Site Settings. Upload your solution and make sure it’s activated.

Note: If you see any error like "Missing site collection feature IDs" then please activate them using the below PowerShell. In case if the reported features are not important for the solution and the quick fix is going back to Onet.xml, finding the referred GUID’s and remove the entries/lines from the file. Once saved you have to go back and re-create the CAB/WSP file and upload the new one.

#  -> $sUserName: User Name to connect to the SharePoint Online Site Collection.

#  -> $sPassword: Password for the user.

#  -> $sSiteColUrl: SharePoint Online Site Collection

#  -> $sFeatureGuid: GUID of the feature to be enabled     

    $host.Runspace.ThreadOptions = "ReuseThread"     

    #Definition of the function that allows to enable a SPO Feature
    function Enable-SPOFeature
    {
        param ($sSiteColUrl,$sUserName,$sPassword,$sFeatureGuid)
        try
        {    
            #Adding the Client OM Assemblies        
            Add-Type -Path "F:\microsoft.sharepointonline.csom.16.1.8412.1200\lib\net45\Microsoft.SharePoint.Client.dll"
            Add-Type -Path "F:\microsoft.sharepointonline.csom.16.1.8412.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll"

            #SPO Client Object Model Context

            $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl) 

            $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUsername, $sPassword)  

            $spoCtx.Credentials = $spoCredentials      

            Write-Host "----------------------------------------------------------------------------"  -foregroundcolor Green

            Write-Host "Enabling the Feature with GUID $sFeatureGuid !!" -ForegroundColor Green

            Write-Host "----------------------------------------------------------------------------"  -foregroundcolor Green

            $guiFeatureGuid = [System.Guid] $sFeatureGuid

            #############################################

            # todo: change object: $spoSite=$spoCtx.Site | $spoSite=$spoCtx.Web

            $spoSite=$spoCtx.Site

            # todo: change scope: [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None | Farm | Site | Web

            # https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.featuredefinitionscope.aspx?f=255&MSPPError=-2147217396

            $spoSite.Features.Add($sFeatureGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)

            #############################################

            $spoCtx.ExecuteQuery()

            $spoCtx.Dispose()
        }
        catch [System.Exception]
        {
          write-host -f red $_.Exception.ToString()   
        }    
    }

    #Required Parameters

    $sSiteColUrl = "https://tenant.sharepoint.com/sites/SharePointMigration/"

    $sUserName = "liakathali.mohammed@doman.com"

    $sFeatureGuid= "c6561405-ea03-40a9-a57f-f25472942a22"

    $sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString 

    Enable-SPOFeature -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sPassword $sPassword -sFeatureGuid $sFeatureGuid

Once you activate the missing features, you should be able to see the newly installed below the Custom tab for the template selection.

No comments:

Post a Comment