Grazie a LinqToXML il compito può esser facilmente svolto
Il codice non è completo, ma bastano queste poche righe per capire come poter continuare ed ottenere tutti i dati necessari per completarlo:
public class ListInformation { public ListUserPermissions { get; set; } public List ItemPermissions { get; set; } } public class UserPermission { public string Username { get; set; } public List<string> Permissions { get; set; } } public class ItemPermission { public string Title { get; set; } public List<string> Permissions { get; set; } } private void GenerateXml(SPWeb spWeb, string spListName) { SPList myList = spWeb.Lists[spListName]; var roleAssignments = myList.RoleAssignments; var myListInformation = new ListInformation(); var lstPermissions = new List (); foreach (SPRoleAssignment roleAssignment in roleAssignments) { var roles = (from SPRoleDefinition roleDefinition in roleAssignment.RoleDefinitionBindings select roleDefinition.Name).ToList(); lstPermissions.Add(new UserPermission { Username = roleAssignment.Member.Name, Permissions = roles }); } myListInformation.UserPermissions = lstPermissions; var permissionXml = new XElement("List", new XElement("Permissions", from userPermission in myListInformation.UserPermissions select new XElement("User", new XAttribute("Username", userPermission.Username), new XElement("Permissions", from perm in userPermission.Permissions select new XElement("Permission", perm))))); var items = myList.Items; var itemPermissions = new List (); foreach (SPListItem item in items) { var roles = (from SPRoleAssignment roleDefinition in item.RoleAssignments select roleDefinition.RoleDefinitionBindings.).ToList(); itemPermissions.Add(new ItemPermission() { Title = item.Title, Permissions = roles }); } permissionXml.Add(new XElement("ItemsCollection", from item in itemPermissions select new XElement("Item", new XAttribute("Title", item.Title), new XElement("Permissions", from perm in item.Permissions select new XElement("Permission", perm))))); permissionXml.Save(@"C:\temp\AWEmpPOs.xml");
buona lettura
No comments:
Post a Comment