Empty your SharePoint site's recycle bin (_layouts/recyclebin.aspx
) and the Admin recycle bin (/_layouts/AdminRecycleBin.aspx
)
Next, check that the masterpage you are trying to delete is not selected in either Masterpage for website or System Master Page at /_layouts/ChangeSiteMasterPage.aspx
.
Try to delete the masterpage now. If it is still unable to delete it, go back to /_layouts/ChangeSiteMasterPage.aspx
and select "Reset all subsites, so they inherit the setting for the site master page" for both Masterpage for website and System Master Page with the new masterpage you want to use selected and click OK.
If this does not solve it and the error persists, try using powershell to find which subsites that are not affected by the above changes.
Update
One way of deleting a master page from the master page gallery is by doing the following:
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$spWeb = Get-SPWeb "http://sharepoint.site.com/"
$masterpageGallery = $spWeb.GetFolder("_catalogs/masterpage")
$masterpage = $masterpageGallery.Files["MyMasterPage.master"]
$masterpage.Delete();
$spWeb.Dispose();