Adding Content Type to List/Library Programatically

Leave a Comment

Hi All,

below example will explain how to associate a content type with list in sharepoint.
           
              SPList oList = oWeb.Lists.TryGetList("ListName");
                SPContentType cType = oWeb.ContentTypes["ContentTypeName"];
                if (cType != null)
                {
                   //enabling the content type for the list
                    oList.ContentTypesEnabled = true;
                    //associating content type with list
                    oList.ContentTypes.Add(cType);
                    oList.Update();
                 }

Related Post

0 comments:

Post a Comment