Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void buttonShowLibaries_Click(object sender, EventArgs e)
- {
- // Configure credentials
- url = textBoxServer.Text;
- buttonUpload.Enabled = false;
- if (!url.Contains("https://"))
- {
- MessageBox.Show("Please enter a valid URL.");
- return;
- }
- string user = "admin@ThomasMoreStudent06.onmicrosoft.com";
- SecureString password = new SecureString();
- foreach (char c in "TMPassword06")
- {
- password.AppendChar(c);
- }
- // Connect to the sitecollection
- using (clientContext = new ClientContext(url))
- {
- // Load the lists
- clientContext.Credentials = new SharePointOnlineCredentials(user, password);
- ListCollection listCollection = clientContext.Web.Lists;
- clientContext.Load(listCollection, lists => lists.Include(
- list => list.Title)
- .Where(list => list.BaseType == BaseType.DocumentLibrary)
- );
- clientContext.ExecuteQuery();
- foreach (List l in listCollection)
- {
- if (DoesUserHavePermissions(l.Title, PermissionKind.DeleteListItems))
- {
- listBoxLibraries.Items.Add(l.Title);
- }
- }
- }
- }
- private bool DoesUserHavePermissions(string name, PermissionKind permmask)
- {
- try
- {
- List TargetList = clientContext.Web.Lists.GetByTitle(name);
- clientContext.Load(TargetList, T => T.EffectiveBasePermissions);
- clientContext.ExecuteQuery();
- return TargetList.EffectiveBasePermissions.Has(permmask);
- }
- catch
- {
- //log
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement