FieldCollection.AddFieldAsXml method

Creates a field based on the specified schema, Boolean value, and field options.

Namespace:  Microsoft.SharePoint.Client
Assembly:  Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)


Public Function AddFieldAsXml ( _
    schemaXml As String, _
    addToDefaultView As Boolean, _
    options As AddFieldOptions _
) As Field
Dim instance As FieldCollection
Dim schemaXml As String
Dim addToDefaultView As Boolean
Dim options As AddFieldOptions
Dim returnValue As Field

returnValue = instance.AddFieldAsXml(schemaXml, _
    addToDefaultView, options)
public Field AddFieldAsXml(
    string schemaXml,
    bool addToDefaultView,
    AddFieldOptions options


  • schemaXml
    Type: System.String

    A Collaborative Application Markup Language (CAML) string that contains the schema.

    It must not be a null reference (Nothing in Visual Basic). It must not be empty. It must be a valid Collaborative Application Markup Language (CAML) string according to the schema specified in [MS-WSSFO2], section

  • addToDefaultView
    Type: System.Boolean

    Specifies to add the field to the default list view.

    true if the field is added to the default list view; otherwise, false.

Return value

Type: Microsoft.SharePoint.Client.Field
A Field object that represents the new field.


Exception Condition

One or more field types are not installed properly, the formula is empty for the calculated field type, or an error occurred during the processing of the specified XML. Error code: -2146232832.

One or more field types are not installed properly. Error code: -2130575340.

Formula is empty for the calculated field type. Error code: -2130575199.


The throttling limit is reached. Error code: -2147024860.

There is a join throttle failure. Error code: -2147024749.


The field with the specified internal name or title does not exist in the collection at the given scope. Error code: -2147024809.


The current user has insufficient permissions. Error code: -2147024891.


This code example creates a field based on schema information and then displays the available fields in the Announcements list, including the new field.

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointFoundation.Samples
    class AddFieldAsXmlExample
        static void Main()
            string siteUrl = "http://MyServer/sites/MySiteCollection";

            ClientContext clientContext = new ClientContext(siteUrl);
            Web site = clientContext.Web;
            List targetList = site.Lists.GetByTitle("Announcements");
            FieldCollection collField = targetList.Fields;

            string fieldSchema = "<Field Type='Text' DisplayName='NewField' Name='NewField' />";
            collField.AddFieldAsXml(fieldSchema, true, AddFieldOptions.AddToDefaultContentType);


            Console.WriteLine("NewField added to Announcements list.\n\nThe following fields are available:\n\n");
            foreach (Field myField in collField)

See also


FieldCollection class

FieldCollection members

Microsoft.SharePoint.Client namespace