Wednesday, August 3, 2011

Add Content types to List or Library in Sharepoint 2010 programmatically

private void AddContentTypesToLibrary(SPList list, SPWeb oWeb)
        {
            list.ContentTypesEnabled = true;
            SPContentTypeCollection ctypecoll = oWeb.ContentTypes;

            foreach (SPContentType ctType in ctypecoll)
            {
            
                    if (list.ContentTypes[ctType.Name] == null)
                    {
                        //ctType.Hidden = true;
                        list.ContentTypes.Add(ctType);
                        

                    }
            
            }
        }

No comments:

Post a Comment

Followers

Blog Archive