SharePoint Blog

Leave a comment

This functionality is unavailable for field collections not associated with a list

For my scenario the above issue occurs when I try to add a field to the content type i.e. when i use ContentType.AddField.

I have solved the above issue by using SPFieldLink instead of SPField

Below is code for your reference

SPContentType cDocumen = newSPContentType(null,Web.ContentTypes,“MyDocument”);


Web.Fields.Add(“Autor”, SPFieldType.Text, false);

SPFieldLink SPFLautor = newSPFieldLink(miWeb.Fields[“Autor”]);ctDocumento.FieldLinks.Add(SPFLautor);