Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I add a new column to a SharePoint list (the list is built on a content type) like this:

        SPField textfield = list.Fields.CreateNewField(SPFieldType.Text.ToString(), "new column");
        list.Fields.Add(textfield);            
        list.Update();

        //the new field must be editable!
        SPField newField = list.Fields["new column"];
        newField.ShowInEditForm = true;
        newField.ShowInViewForms = true;
        newField.ShowInDisplayForm = true;
        newField.ShowInNewForm = true;
        newField.Update();

        //update the view
        SPView view = list.DefaultView;
        view.ViewFields.Add(language);
        view.Update(); 

The new column appears in the default view of the list and everything appears to work just fine. However, when I try to add a new item or edit an existing item, my new column doesn't appear in the form. A quick look in PowerShell reveals that "CanBeShowInEditForm" is set to true. What am I missing here?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Your missing adding the field as fieldlink to the Lists version for the content type

var ct = list.ContentTypes["NameOfCT"];
var fieldLink = new SPFieldLink(newField);
ct.FieldLinks.Add(fieldLink);
ct.Update()

When you're using content types in a list only the fields corresponding to the content type is shown in forms. But all fields can be shown in views.

share|improve this answer
add comment

Your Answer

 
discard

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.