private void ChangeOrHideContentTypesInALibrary(SPList list)
{
//************ start :hiding content types for working document list subfolders ***************//
SPFolderCollection folderCol = list.RootFolder.SubFolders;
foreach (SPFolder folder in folderCol)
{
HideContentTypeByFolder(folder, list);
}
//************ start :hiding root level content types ***************//
orderedContentTypes = new List<SPContentType>();
list.RootFolder.UniqueContentTypeOrder = null;
list.RootFolder.Update();
foreach (SPContentType ct in list.RootFolder.ContentTypeOrder)
{
if (ct.Name.Contains("Select Content Type"))
{
ct.Hidden = true;
}
if (ct.Name.Contains("Select Content Type")) // || ct.Group.Contains("Lending Processes"))
{
//ct.Hidden = false;
orderedContentTypes.Add(ct);
}
}
if (orderedContentTypes != null && orderedContentTypes.Count > 0)
{
if (orderedContentTypes.Count > 0)
{
orderedContentTypes.Reverse();
}
list.RootFolder.UniqueContentTypeOrder = orderedContentTypes;
list.RootFolder.Update();
}
}
private void HideContentTypeByFolder(SPFolder folder, SPList documentLibrary)
{
orderedContentTypes = new List<SPContentType>();
int i = 0;
//foreach (SPContentType ct in documentLibrary.ContentTypes) // u can use one of them
foreach (SPContentType ct in folder.ContentTypeOrder)
{
if (ct.Group.Contains("Collab " + folder.Name))
{
ct.Hidden = false;
orderedContentTypes.Add(ct);
//orderedContentTypes[i].Hidden = false;
}
if (ct.Name.Contains("Select Content Type"))
{
orderedContentTypes.Add(ct);
}
i++;
}
if (orderedContentTypes != null && orderedContentTypes.Count > 0)
{
folder.UniqueContentTypeOrder = orderedContentTypes;
folder.Update();
}
}
No comments:
Post a Comment