0 out of 1 rated this helpful Rate this topic

SPFieldCollection.AddFieldAsXml Method (String)

Windows SharePoint Services 3
Creates a field based on the specified schema.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
public string AddFieldAsXml (
	string strXml
)

Parameters

strXml

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

Return Value

A CAML string that contains the name of the new field.

The following code example uses CAML to define a field and adds the field to the specified list.

using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["MySite"])
{
    SPFieldCollection collFields = oWebsite.Lists["MyList"].Fields;

    string strNewField = "<Field Type=\"Calculated\" " +
    "DisplayName=\"New_Field_Display_Name\" ResultType=\"Currency\" " +
    "ReadOnly=\"TRUE\" Name=\"New_Field_Internal_Name\">" +
    "<Formula>=Currency_Field_Name*100</Formula>" +
    "<FieldRefs><FieldRef Name=\"Currency_Field_Name\" />" + 
    "</FieldRefs></Field>";

    collFields.AddFieldAsXml(strNewField);
}
NoteNote:

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
local device name is already in use Exception
http://www.sharepoint-tips.com/2010/07/local-device-name-is-already-in-use.html

well known error associated with this method.