sharepoint-2010splistspfield

Use the custom SPFieldType when adding new column


I would like to know how to use the custom SPFieldType (Existing on the Site) when adding new SPList column.

E.g. [Normal way using the SPFieldType.Text field type]

list.Fields.Add("Location", SPFieldType.Text, true);
list.Update();

How about for the custom field type?

list.Fields.Add("Location", [Custom SPField Type], true); ?

Thanks in advance.


Solution

  • Instead of Add, try AddFieldAsXml.

    For more information, see Programmatically creating a field (column) from the Custom field type.