Hide and Unhide Sharepoint fields through reflection
Posted by sNjY on July 28, 2008
There were couple of fields that were created as part of content type and enabled in a document libraries.
As the fields need not be shown in list diplay form, they were set to hidden but search could not index them and eventually searching based on those fields was not possible. So decided to unhide those fields through WSSListConfigurator tool downloaded from codeplex but the system didn’t allow to unhide the fields The reason was that the fields hidden property was dependent on another property called cantogglehidden. The cantogglehidden property was readonly and could not be changed.
But with this piece of code below, it was all possible, Code is self explainatory…
SPSite site = new SPSite(“http://ressintspwebd01:99“);
SPWeb web = site.RootWeb;
web.AllowUnsafeUpdates =
true;
SPField spfield = web.Lists["Policies"].Fields["Document Type"];
Type type = spfield.GetType();
MethodInfo mi = type.GetMethod(“SetFieldBoolValue”,
BindingFlags.NonPublic | BindingFlags.Instance);
mi.Invoke(spfield,
new object[] { “CanToggleHidden”, true });
spfield.Hidden =
false;
spfield.Update();
Thanks to jigar for sharing tis piece of useful code.
This entry was posted on July 28, 2008 at 10:28 pm and is filed under Technology. Tagged: hide unhide fields through reflection, sharepoint cantogglehidden, sharepoint fields, sharepoint hidden. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.



Faizan Ahmed said
I really appreciate this solution. I had night mare with Cross List issue but you solution has resolved my issue.
Jason said
Hello -
quick question:
how do i hide the option “view all responses” once a participant completes a survey?
bazztrap said
http://spyralout.com/2009/09/18/masking-sharepoint-created-by-and-modified-by-making-list-anonymous/