Wednesday, December 21, 2016

Fix "Another site or list is still using this content type. If you would still like to delete it, please remove the content type from all sites and lists and then try again" in SharePoint

Problem:
When trying to delete a content type from List or site, received below error in SharePoint online site
"Another site or list is still using this content type. If you would still like to delete it, please remove the content type from all sites and lists and then try again."

Another site or list is still using this content type. If you would still like to delete it, please remove the content type from all sites and lists and then try again.
Solution:
Find the references where a particular content type is being used and remove the content type association from the list. (You may have to delete the items of the particular content type or change the content type of the items, in order to remove the content type association from list). Also remove the items from both 1st stage (End-user) Recycle bin and 2nd stage (Administrator) recycle bins!

PowerShell to Find a Content Type Usage in SharePoint Online:
This PowerShell script scans get exports a content type references with in a given site collection.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Get-ContentTypeUsage()
{ 
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ContentTypeName,
        [Parameter(Mandatory=$true)] [string] $ReportFile        
    )

    Try {
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
        Write-host "Processing Site:"$SiteURL
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
    
        #Get the content type from web
        $ContentTypeColl = $Ctx.Web.ContentTypes
        $Ctx.Load($ContentTypeColl)
        $Ctx.ExecuteQuery()
        
        #Array to hold result
        $Results = @()

        #Get all lists and libraries from the site
        $Ctx.Load($ctx.Web.Lists)
        $Ctx.Load($Ctx.Web.Webs)
        $Ctx.ExecuteQuery()

        Foreach($List in $Ctx.Web.Lists)
        {
            $Ctx.Load($List.ContentTypes)
            $Ctx.ExecuteQuery()
       
            #Check if the content type exists in the list        
            $ContentType = $List.ContentTypes | Where {$_.Name -eq $ContentTypeName}
            If($ContentType -ne $Null)
            { 
                $Results += New-Object PSObject -Property @{
                'Site' = $SiteURL
                'List Name' = $List.Title
                'URL'= $SiteURL+$List.DefaultViewURL
                }
                Write-host "Found Content Type Reference at '$($List.Title)' in site '$SiteURL'" -f Green
            }
        }
        #Export Results to CSV
        $Results | Export-Csv $ReportFile -Append -NoTypeInformation

        #Process subsites - Call the function recursively
        If($Ctx.Web.Webs.Count -gt 0)
        {
            Foreach ($web in $Ctx.Web.Webs)
            {
                Get-ContentTypeUsage -SiteURL $web.Url -ContentTypeName $ContentTypeName -ReportFile $ReportFile
            }
        }
  }
    Catch {
        write-host -f Red "Error Deleting Content Type!" $_.Exception.Message
    }
}

#Set parameter values
$SiteURL="https://crescent.sharepoint.com/"
$ContentTypeName="Project Template"
$ReportFile="C:\Temp\ContentTypeRef.csv"

#Delete the Output report file if exists
if (Test-Path $ReportFile) { Remove-Item $ReportFile }

#Call the function
Get-ContentTypeUsage -SiteURL $SiteURL -ContentTypeName $ContentTypeName -ReportFile $ReportFile

Here is the similar similar solution for SharePoint on-premises: How to resolve Content Type in Use Error in SharePoint?



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!


You might also like:

Related Posts Plugin for WordPress, Blogger...