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 have two content types that I want to use to more than one list.

I want to add a Field to ONLY one of those lists, but I want to add the field to both the content types of the list, without modifind the content types. If i only add the field to the list with the Lists.Create() method , the filed is added only to the first oh the content types.

I can use the FieldLink.Add() method but it will propagate the change also to the other lists.

Here is my code: it works for my list but it also propagate the change of the CT to the other lists.

SPList list = Lists.Create(web, Constants.LIST_NAME_TOPCLICKED, Constants.CT_ID_ARTICOLO_IMM);

if (list != null)

{  

list.ContentTypes.Add(web.ContentTypes[new SPContentTypeId(Constants.CT_ID_ARTICOLO_VID)]);

list.Update();               

list.Fields.Add(Constants.AF_VISUALIZZA, SPFieldType.Boolean, true);

SPField fld = list.Fields.GetField(Constants.AF_VISUALIZZA);             

SPFieldLink fl = new SPFieldLink(fld);         

SPContentType ct = list.ContentTypes[Constants.CT_AV];

ct.FieldLinks.Add(fl);           

ct.Update();              

ct = list.ContentTypes[Constants.CT_AI];

ct.FieldLinks.Add(fl);               

ct.Update();

list.Update();

}

the field name is Constants.AF_VISUALIZZA the two contenttypes name are Constants.CT_AV and Constants.CT_AI.

how can i resolve this?

share|improve this question
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.