Guest User

Untitled

a guest
Sep 5th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. var tenantAdminSiteUrl = "https://tenant-admin.sharepoint.com";
  2. var siteCollectionUrl = "https://tenant.sharepoint.com/sites/Test";
  3.  
  4. var userName = "admin@tenant.onmicrosoft.com";
  5. var password = "password";
  6.  
  7. using (ClientContext clientContext = new ClientContext(tenantAdminSiteUrl))
  8. {
  9. SecureString securePassword = new SecureString();
  10. foreach (char c in password.ToCharArray())
  11. {
  12. securePassword.AppendChar(c);
  13. }
  14.  
  15. clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
  16. clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
  17.  
  18. var tenant = new Tenant(clientContext);
  19. var siteProperties = tenant.GetSitePropertiesByUrl(siteCollectionUrl, true);
  20. tenant.Context.Load(siteProperties);
  21. tenant.Context.ExecuteQuery();
  22.  
  23. siteProperties.DenyAddAndCustomizePages = DenyAddAndCustomizePagesStatus.Disabled;
  24. var operation = siteProperties.Update();
  25. tenant.Context.Load(operation, op => op.IsComplete, op => op.PollingInterval);
  26. tenant.Context.ExecuteQuery();
  27.  
  28. // this is necessary, because the setting is not immediately reflected after ExecuteQuery
  29. while (!operation.IsComplete)
  30. {
  31. Thread.Sleep(operation.PollingInterval);
  32. operation.RefreshLoad();
  33. if (!operation.IsComplete)
  34. {
  35. try
  36. {
  37. tenant.Context.ExecuteQuery();
  38. }
  39. catch (WebException webEx)
  40. {
  41. // catch the error, something went wrong
  42. }
  43. }
  44. }
  45. }
Add Comment
Please, Sign In to add comment