I am doing a loop through for all the folders within a document library and wanna apply the Read permissions to a custom SPGroup.
How can i achieve the same?
Though i have written the code, by storing all the folder names from the doc lib into a generics ILIST
object and then iterating thru these ILIST
applying the permissions.
But it doesn't work. How to achieve the same? shouldn't i store the SPLISTITEM
onto a ILIST
OBJECT ?
IList<SPListItem> allFolderItems_BI = new List<SPListItem>();
SPDocumentLibrary objBENCHMARKINDEXDocLibrary =
paramCurrentWeb.Lists.TryGetList("BenchmarkIndex") as
SPDocumentLibrary;
if (objBENCHMARKINDEXDocLibrary != null &&
objBENCHMARKINDEXDocLibrary.Folders.Count > 0)
{
SPQuery query = new SPQuery();
//Condition to check the item type is folder or not
query.Query = "<Where><Eq><FieldRef Name='FSObjType'/><Value
Type='Lookup'>1</Value></Eq></Where>";
//Retrieve the items based on Query
SPListItemCollection folderItems =
objBENCHMARKINDEXDocLibrary.GetItems(query);
string folderDetails = "";
//Get the name and Url for the folder
foreach (SPListItem singleFolderitem in folderItems)
{
folderDetails = singleFolderitem.Name;
allFolderItems_BI.Add(singleFolderitem);
}
if (allFolderItems_BI != null && allFolderItems_BI.Count >
0)
{
foreach (var singleFolderNamein_BI in allFolderItems_BI)
{
//if(singleFolderNamein_BI.HasUniqueRoleAssignments)
{
SPRoleAssignment
roleAssignmentFolderGroup_NPH_BI = new SPRoleAssignment(paramobjNPHDivGroup);
SPRoleDefinition
roleDefinitionFolderGroup_NPH_BI =
paramCurrentWeb.RoleDefinitions["NPD ReadILP"];
roleAssignmentFolderGroup_NPH_BI.RoleDefinitionBindings.Add
(roleDefinitionFolderGroup_NPH_BI);
singleFolderNamein_BI.RoleAssignments.Add
(roleAssignmentFolderGroup_NPH_BI);
//singleFolderNamein_BI.Update();
}
}
}
//folderDetails += "Folder Name:" + item.Name + "<br/>Folder
URL:" + spWeb.Url + "/" + item.Url + "<br/>";
}