Friday, August 29, 2008

How to add Hidden Field programmatically in MOSS

Hi All,

Just in the reference of my earlier post add multi line of text programmatically, i come to know about one more thing.

I actually wanted to add one Hidden field in the list which also cannot be seen at the time of UI. we know that there is a property called Hidden that can be set to true and false.

But..but.. just try once, you will get an Error. Just Try this,

String Fieldid = spList.Fields.Add("", SPFieldType.Text, false);
SPField objfield = spList.Fields.GetField(Fieldid );
objfield.Hidden = true;

And, see you will get and Error. The Error is because CanToggleHidden property of the Field is set to false, as a name suggest you cannot toggle the hidden property and that even cannot be set by code using property bag.

so all you need to do is use the same approach as i described in my previous post.
add multi line of text programmatically,

The difference is only this,

list.Fields.AddFieldAsXml("Type=\"Boolean\" Required=\"FALSE\" Name=\"yourfieldname\"
CanToggleHidden=\"TRUE\" Hidden=\"TRUE\"/>");

Here you actually set CanToggleHidden to TRUE and only because of this, you can change the Hidden to True in XML. this is not possible by directly setting the properties.

And then just set the Title Property to display name that you want.

There you go, now you will have the hidden field in your list.

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to