开发者

can't delete site columns that aren't referenced

开发者 https://www.devze.com 2023-02-09 09:53 出处:网络
I just created a couple of site columns and content types that reference them through VS2010.I updated one of the fields and then tried to redeploy, but after retracting, deploy failed because the sit

I just created a couple of site columns and content types that reference them through VS2010. I updated one of the fields and then tried to redeploy, but after retracting, deploy failed because the site columns previously created were still there. I tried to delete them manually from the UI, and got an alert box with this message:

Site columns which are included in content types cannot be deleted. Remove all references to this site column prior to deleting it.

I dug around in SharePoint Manager and didn't find any references, so I used powershell to enumerate all the content types and lists looking for references to my site columns and found nothing.

I tried to delete using PowerShell like this:

$web.Fields.Delete("StartTime")

which resulted in this error:

Exception calling "Delete" with "1" argument(s): "Site columns which are included in 
content types or on lists cannot be deleted. Please remove all instances of this site 
column prior to deleting it."
At line:1 char:19
+ $web.Fields.Delete <<<< ("StartTime")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Finally, a simple inspection of the columns in PowerShell shows the following:

Title                               Id                                                         CanBeDeleted ParentList                                                       Sealed ListsFieldUsedIn                   
-----                               --                                                         ------------ ----------                                                       ------ ----------------                   
Start Time OBE                      6fa0d85b-9af1-408b-835f-d4c66536...                                True                                                                   False {}                                 
Time Tracker Tags                   92bc866b-0415-45f0-b431-d4df69c4.开发者_JAVA技巧..                                True                                                                   False {}                                 

I'm experienced with MOSS 2007 and new to SP2010, but I've never seen this happen before. Anyone have any hints?


Your need to find and remove both the content types that use the site column and also any lists or libraries that use the site column you are trying to delete. Use PowerShell to get the site column object using something like this:

 $column = $web.Fields[“Column Display Name”]

Then find all the places where it is used, using something like this:

$column.ListsFieldUsedIn()

which spits out two GUIDs -- the WebID and ListID -- of every place that uses this content type.

Below is a PowerShell script that loops over all the list GUIDs returned from ListFieldUsedIn() and then finds the subweb and list matching that GUID and prints out list name and subweb URL for each usage :

$site = Get-SPSite "http://sharepoint"
$rootweb = $site.rootweb
$siteColumnToRemove = "Column Display Name”
$sc = $rootweb.Fields[$siteColumnToRemove]
if ($sc)
{
    write-host "  Found Site Column '" $sc.Title "' in gallery" -ForegroundColor Gray
    foreach( $listusage in $sc.ListsFieldUsedIn() )
    {
        $listID = $listusage.ListID            
        foreach ($subweb in $site.allwebs)
        {
            foreach ($list in $subweb.lists)
            {
                if ($list.ID -eq $listID)
                {                     
                     write-host "    Site Column '" $sc.Title "' used in list '" $list.Title "' in site '" $subweb.Url "'" -BackgroundColor Yellow -ForegroundColor Black
                }
            }
        }
    }
}


Happens to SharePoint 2010 too. Try looking at:

$field.AllowDeletion = $TRUE
$field.Update()

When I set that, seemed to work. Now I just can't replicate it, in order to prove my point. Typical.


I had this same problem and was able to delete using SharePoint Designer - not sure if anyone can validate this works for them.


It's been a while, and I've long since moved on from this problem, but I think that the final answer was that there were content types relying on a particular site column that weren't picked up by SPM.

I think once I retracted everything custom from the site, I was able to delete normally.


My guidance is that you should never delete a site column once it's in use. I've seen site collections become completely unusable because of issues trying to delete site columns or content types.

If you no longer need the site column, just hide it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号