SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i had create a list programmatically on Feature_activated. Now i want to add a new Field to my list with an XML File on UpgradeActions from the Feature. I know the solution for add a Field with C#.



share|improve this question
As I understood you need to add new field to existing list in method FeatureUpgrading in Feature Receiver. Am I right? – Andrew Apr 25 '13 at 15:12
Yes you are right, i need an example with xml – gidion1983 Apr 26 '13 at 8:35

I implemented similar behavior some time ago, I used xml file with following structure:

<?xml version="1.0" encoding="utf-8" ?>
<Fields ListUrl="Lists/Test">
  <Field ID="{1174073D-CD08-4A8A-A70E-5199200E04AC}" 
         DisplayName="TestField" />

To deserialize xml file I used following class:

public class FieldsConfiguration
    public string ListUrl { get; set; }

    public List<Field> Add { get; set; }

public class Field
    public string ID { get; set; }

    public string Name { get; set; }

    public string Type { get; set; }

    public string List { get; set; }

I added xml file to feature definition. To get xml file name in my feature receiver I used code:

string fileName = Path.Combine(properties.Definition.RootDirectory, "FileName.xml");

Method that applies changes to list:

    /// <summary>
    /// Method adds fields to list from xml file.
    /// </summary>
    /// <param name="config">Deserialized xml file</param>
    /// <param name="doc">XmlDocument of xml file</param>
    /// <param name="web">Current web</param>
    /// <param name="list">Current list</param>
    protected void AddFieldsFromFile(FieldsConfiguration config, XmlDocument doc, SPWeb web, SPList list)
        foreach (var field in config.Add)
            //check if field is already exist
            if (list.Fields.ContainsField(field.Name))
            //get field schema from xml
            var fieldSchema = doc.SelectSingleNode(string.Format("/Fields/Add/Field[@Name='{0}']", field.Name));
            if (fieldSchema == null || fieldSchema.Attributes == null)
            //hack for Lookup fields
                var lookupList = web.GetListNoThrow(field.List);
                if (lookupList == null)

                fieldSchema.Attributes["List"].Value = lookupList.ID.ToString();
            list.Fields.AddFieldAsXml(fieldSchema.OuterXml, false, SPAddFieldOptions.AddFieldInternalNameHint);

Provided code supports all field types except Taxonomy fields.

share|improve this answer
Thank you for your code, in your example, i must write Code for add a new field to a SharePoint list. Can i use your xml file to add a fiedd on feature upgrade without code? – gidion1983 Apr 29 '13 at 8:07
Check this link… – Andrew Apr 29 '13 at 8:33
This is not the Solution i need, i found this post… the MyField2 are add to an ContentTyp but i do not have a content Type i was create the List with c#. Is it posible to Update this List without c# ? – gidion1983 Apr 29 '13 at 15:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.