Advertisement
Guest User

Aangepaste code voorbeeld sebastiaan

a guest
Dec 9th, 2017
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. private void buttonShowLibaries_Click(object sender, EventArgs e)
  2. {
  3. // Configure credentials
  4. url = textBoxServer.Text;
  5. buttonUpload.Enabled = false;
  6.  
  7. if (!url.Contains("https://"))
  8. {
  9. MessageBox.Show("Please enter a valid URL.");
  10. return;
  11. }
  12.  
  13. string user = "admin@ThomasMoreStudent06.onmicrosoft.com";
  14. SecureString password = new SecureString();
  15. foreach (char c in "TMPassword06")
  16. {
  17. password.AppendChar(c);
  18. }
  19.  
  20. // Connect to the sitecollection
  21. using (clientContext = new ClientContext(url))
  22. {
  23. // Load the lists
  24. clientContext.Credentials = new SharePointOnlineCredentials(user, password);
  25.  
  26.  
  27. ListCollection listCollection = clientContext.Web.Lists;
  28. clientContext.Load(listCollection, lists => lists.Include(
  29. list => list.Title)
  30. .Where(list => list.BaseType == BaseType.DocumentLibrary)
  31. );
  32. clientContext.ExecuteQuery();
  33.  
  34. foreach (List l in listCollection)
  35. {
  36. if (DoesUserHavePermissions(l.Title, PermissionKind.DeleteListItems))
  37. {
  38. listBoxLibraries.Items.Add(l.Title);
  39. }
  40. }
  41. }
  42. }
  43.  
  44. private bool DoesUserHavePermissions(string name, PermissionKind permmask)
  45. {
  46. try
  47. {
  48. List TargetList = clientContext.Web.Lists.GetByTitle(name);
  49. clientContext.Load(TargetList, T => T.EffectiveBasePermissions);
  50. clientContext.ExecuteQuery();
  51. return TargetList.EffectiveBasePermissions.Has(permmask);
  52. }
  53. catch
  54. {
  55. //log
  56. return false;
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement