I have the code below and up the fld.Update()
line, it crashes saying
This functionality is unavailable for field collections not associated with a list
The string values I provided are fine.
SPContentType ctype = list.ContentTypes["x"];
SPField fld = ctype.Fields.GetField("x");
if (!list.Fields.ContainsField("x"))
{
list.Fields.Add(fld);
}
fld.ShowInDisplayForm = true;
fld.ShowInEditForm = true;
fld.ShowInNewForm = true;
fld.Update();
ctype.Update();
How should this code be written?
EDIT: What I am trying to do is add a field from a content type (All the doc libs use the content type), display that field in the document library's view form (recursively, so within folders etc), and then copy text from one field to another.