I can get to the document library folder/item like this:
SPDocumentLibrary docList = (SPDocumentLibrary)web.Lists["Documents"];
string caml = "<Where><Eq><FieldRef Name='ID' /><Value Type='Integer'>" + id + "</Value></Eq></Where>";
SPQuery qry = new SPQuery();
qry.Query = caml;
SPListItem fldrItem = null;
SPListItemCollection fldrColl = docList.GetItems(qry);
if (fldrColl.Count > 0)
{
fldrItem = fldrColl[0];
}
This is not a complete example, but what I want to do is to determine what groups have what permission on that fldrItem
, add it to a dictionary object in the form of "group", "permission", and eventually I'll write that dictionary out into a DataTable
and bind that to a GridView
. But, so, inside that last bracket, I want to do something like:
bool hasPerms = false;
Dictionary<string, string> permsDict = new Dictionary<string, string>();
foreach (SPGroup group in web.Groups)
{
SPBasePermissions perms = SPBasePermissions.EditListItems;
if (fldrItem.DoesUserHavePermissions(group, perms)) // <-- has to use SPUser, not SPGroup, so how do I check group permissions?
{
if (docList.WriteSecurity == 4) //None
{
hasPerms = false;
permsDict.Add(group.Name, "None");
}
else if (docList.WriteSecurity == 2) //Only their own
{
if (fldrItem["Creator"].ToString() == SPContext.Current.Web.CurrentUser.LoginName)
{
hasPerms = true;
permsDict.Add(group.Name, "Contribute");
}
}
else
{
hasPerms = true;
if (fldrItem.DoesUserHavePermissions(group, SPPermissionBase.FullMask))
permsDict.Add(group.Name, "Full Control");
}
}
That 5th line is where my issue is --- How do I check for a group's permissions on a document library/list item? And is there a better/easier way to do this than the way I'm attempting?