In some scenarios, user may ask for a field which should not be editable after information has been added to it. Or many times we may want to disallow user to delete that field. This can be easily achieved through code by changing the properties of SPField object.
//Get the field that you want to update
SPField objSPField = objSPWeb.Fields.GetField("Your Field Title");
if (objSPField != null)
{
//change the properties
objSPField.AllowDeletion = true;
objSPField.ShowInDisplayForm = true;
objSPField.ShowInListSettings = false;
objSPField.ShowInEditForm = false;
objSPField.ShowInNewForm = true;
objSPField.Update();
}
//Get the field that you want to update
SPField objSPField = objSPWeb.Fields.GetField("Your Field Title");
if (objSPField != null)
{
//change the properties
objSPField.AllowDeletion = true;
objSPField.ShowInDisplayForm = true;
objSPField.ShowInListSettings = false;
objSPField.ShowInEditForm = false;
objSPField.ShowInNewForm = true;
objSPField.Update();
}
No comments:
Post a Comment