c# - sharepoint : Add existing site column to existing content type Programatically -


var objweb = properties.feature.parent spweb;

spcontenttype contenttype = objweb.contenttypes["wiki page"]; if (!contenttype.fields.containsfield("keywords")) {     spfield field = objweb.fields["keywords"];     spfieldlink fieldlink = new spfieldlink(field);     contenttype.fieldlinks.add(fieldlink);     contenttype.update(true); } 

i use code in feature activation add site column "keyword" site content type "wiki page" problem "keyword" add in "wiki page" not existing site column it's add new site column. there problem in code?

one other thing code works fine on moss server when deploy on office365 problem found

you should try code below:

 if (objweb.isrootweb)  {        spcontenttype contenttype = objweb.contenttypes["wiki page"];     if (!contenttype.fields.containsfield("keywords"))     {       spfield field = objweb.fields["keywords"];       spfieldlink fieldlink = new spfieldlink(field);       contenttype.fieldlinks.add(fieldlink);       contenttype.update(true);     }  }  else  {    spcontenttype contenttyperoot = site.rootweb.contenttypes["wiki page"];    if (!contenttyperoot.fields.containsfield("keywords"))    {      spcontenttype contenttype = site.rootweb.contenttypes["wiki page"];      if (!contenttype.fields.containsfield("keywords"))      {        spfield field = site.rootweb.fields["keywords"];        spfieldlink fieldlink = new spfieldlink(field);        contenttype.fieldlinks.add(fieldlink);        contenttype.update(true);      }    }  } 

i hope being helped code :)


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -