Hi All,
below example will demonstrates how to set the default content type to list/library programmatically 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;
//adding conten type
oList.ContentTypes.Add(cType);
SPContentTypeCollection currentOrder = oList.ContentTypes;
List<SPContentType> result = new List<SPContentType>();
foreach (SPContentType ct in currentOrder)
{
if (ct.Name.Contains("ContentTypeName"))
{
result.Add(ct);
}
}
oList.RootFolder.UniqueContentTypeOrder = result;
oList.Update();
below example will demonstrates how to set the default content type to list/library programmatically 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;
//adding conten type
oList.ContentTypes.Add(cType);
SPContentTypeCollection currentOrder = oList.ContentTypes;
List<SPContentType> result = new List<SPContentType>();
foreach (SPContentType ct in currentOrder)
{
if (ct.Name.Contains("ContentTypeName"))
{
result.Add(ct);
}
}
oList.RootFolder.UniqueContentTypeOrder = result;
oList.Update();
Related Post
Library
- Import Data From XML
- Import Data from Excel to Dataverse using PowerApps
- Column formatting in modern list view
- Get List Field Type using ECMA Script in SP Hosted Apps
- Related Items Column in SharePoint 2013
- Adding Content Type to List/Library Programatically
- Difference between List and Library in SharePoint
0 comments:
Post a Comment