1 out of 1 rated this helpful - Rate this topic

SPFieldCollection.AddFieldAsXml Method

Windows SharePoint Services 3
Creates a field based on the specified schema.
Name Description
SPFieldCollection.AddFieldAsXml (String)
Creates a field based on the specified schema.
SPFieldCollection.AddFieldAsXml (String, Boolean, SPAddFieldOptions)
Creates a field based on the specified schema, Boolean value, and field options.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
AddFieldAsXml
Example

void AddField(SPList list)
{
const string fieldSchemaXml = "<Field Type=\"Integer\" DisplayName=\"Field Display Name\" Required=\"FALSE\" ID=\"{ca63f3f2-106c-4786-9058-a511ae933551}\" StaticName=\"FieldName\" Name=\"FieldName\" />";

list.Fields.AddFieldAsXml(ordinalFieldXml,/*addToDefaultView*/true, SPAddFieldOptions.AddToAllContentTypes);
list.Update();
}

The ID attribute specified in the field schema must a unique GUID for the lists field collection.