Friday 11 May 2012

"I cannot delete this column from my list??" - Well that must be a SharePoint 2010 Peristent column

If  you are viewing this blog post I assume you have not had a very good day at work today! Here's a look at what happened to me -

I recently ran into a problem where one of my users added a site column called "Target Folder" to their SharePoint list and later realized that that column was not required. So the user wanted to delete the "Target Folder" column. That is the most basic SharePoint task that is there to be done and so I wondered that why is this user coming to me for something so trivial.

Alas! Everything in SharePoint is not what it seems. I went to the list settings clicked on the column and I could not find the delete button in fact I could not find any means to edit that column. What happened here? I checked some other columns (Had my farm gone crazy?) No! Every other column in that list (or for that matter in the site) seemed absolutely fine.

After a few hours of digging here and there I turned to Master Google and I was enlightened!

There are a set of site columns which are Persistent site columns and once added to a list these columns cannot be modified or deleted (through the SharePoint UI). Also, if you add these site columns to a custom site content type you will not be able to delete the site content type as well. On attempting to delete the site content type you will get an error stating - "The content type is in use and cannot be deleted" even though you have not used the content type anywhere.

Here is a list of site columns which are persistent:

  1. Active
  2. Aliases
  3. Article Date
  4. Byline
  5. Contact
  6. Contact E-Mail Address
  7. Contact Name
  8. Contact Picture
  9. Custom Router
  10. Image Caption
  11. Page Content
  12. Page Icon
  13. Page Image
  14. Priority
  15. Properties used in Conditions
  16. Property for Automatic Folder Creation
  17. Rollup Image
  18. Route To External Location
  19. Rule Name
  20. Scheduling End Date
  21. Scheduling Start Date
  22. Submission Content Type
  23. Summary Links
  24. Summary Links 2
  25. Target Audiences
  26. Target Folder
  27. Target Library
  28. Target Path
Be very sure before adding these columns to your list or content type.

To delete these site columns from your list you will need to do so by using PowerShell commands as follows:

$web = Get-SPWeb (Your site URL)
$list = $web.Lists[(Your List Name)]
$field = $list.Fields[(Your Column Name)]
$field.AllowDeletion = “true”
$field.Sealed = “false”
$field.Delete()
$list.Update()
$web.Dispose()

And.. I hope the rest of your day (if left) is nice!

14 comments:

  1. Thank you. I would never find solution myself. I also found that:
    1. $field.Sealed = "false" does not change Sealed value (it still is true)
    2. It is not necessary, because I was able to delete by just setting AllowDeletion = "true"

    ReplyDelete
    Replies
    1. Thank you for your comment and the information shared.

      Delete
  2. Im using sharepoint 2013 , but this cod can not work , do u have any other way ?

    ReplyDelete
    Replies
    1. Hi Amin,
      As per my understanding the above code should work for 2013 as well (though I had tried it in 2010 and haven't got a chance to run it for a 2013 installation) from what I have researched you should be able to do the same steps for 2013.
      Are you facing any particular error when executing the above script? Please share more details of your problem.
      Thanks,
      Huzefa Mala.

      Delete
    2. I am using 2013 and I am getting an error with this saying. Exception setting "Sealed": "Operation is not valid due to the current state of the object."
      At line:1 char:1
      + $field.Sealed = "false

      Delete
    3. Sarah can you please post the entire script that you have run along with the error.. A screen clipping would be helpful. Thank you.

      Delete
    4. This comment has been removed by the author.

      Delete
    5. This comment has been removed by the author.

      Delete
  3. I am having the same issue as Sarah. Here's my code:
    $web = Get-SPWeb https://myWeb
    $list = $web.Lists["Technical"]
    $field = $list.Fields["Description-a"]
    $field.ReadOnlyField = $false
    $field.AllowDeletion = $true
    $field.Sealed = $false
    $field.Delete()
    $list.Update()
    $web.Dispose()

    and here are the errors:
    Exception setting "Sealed": "Operation is not valid due to the current state of the object."
    At line:6 char:1
    + $field.Sealed = $false
    + ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

    Exception calling "Delete" with "0" argument(s): "You cannot delete a read-only column."
    At line:7 char:1
    + $field.Delete()
    + ~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SPException

    ReplyDelete
  4. I found the answer to this! Unless it is one of the 'sealed' fields listed above you do not need to set it to false. To be on the safe side, add to this the turning off of 'Read Only':
    $field.ReadOnlyField = $false
    Lastly, reference the field from the 'list' side of things like this:
    $list.Fields.Delete($field)
    Of course, follow it up with 'Update' and 'Dispose'.

    ReplyDelete
  5. I have a similar issue where a content and structure migration created duplicate fields and though their Title's same but internal name is different and I had to delete those fields based on internal name
    My code:

    $web = Get-SPWeb https://myWeb
    $list = $web.Lists["Technical"]
    $field = $list.Fields |?{$_.InternalName -eq "InternalNameofthefield"}
    $field.ReadOnlyField = $false
    $field.AllowDeletion = $true
    $field.Sealed = $false
    #if I dont update prior I can't delete - on sharepoint 2010 so update command first.
    $field.update()
    $field.Delete()
    $list.Update()
    $web.Dispose()

    ReplyDelete
  6. When you have finally finished setting up your web site and you have introduced both your company and the products and services it has to offer. You have included propositions and promotions to attract your target audience's attention. You have built your we site following all of the know dos and don'ts when it comes to building a company web site. What do you need to do to make your company website a great success?ipucum

    ReplyDelete
  7. Nice knowledge gaining article. This post is really the best on this valuable topic. https://view.ly/v/EPuUGO2Zqek0

    ReplyDelete