How to resolve the error “Cannot change hidden attribute for this field”


In this article we will be seeing how to resolve the following error "Cannot change hidden attribute for this field".

I have created a custom content type with one custom column. In the custom column I have given the hidden property to "false".

Solution:

Hidden1.gif

Custom Content Type Elements.xml:

Hidden2.gif

Custom Site Column Elements.xml:

Hidden3.gif

When I was trying to change the hidden property through API with the following code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace SiteColumnModify
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://ukcbemtsekirk01:20/"))
{
using (SPWeb web = site.RootWeb)
{
SPField field = web.Fields["SiteColTest"];
field.Hidden = true;
field.Update();
}
}
}
}
}


I was getting the following error.

Hidden4.gif

How to resolve it:

When you create a custom site column and if you want to change the hidden property make the "CanToggleHidden" property to true. This is read only property. Then try to change the hidden property it will be working fine.
 

Up Next
    Ebook Download
    View all
    Learn
    View all