本文整理汇总了C#中Tenant.SetSiteAdmin方法的典型用法代码示例。如果您正苦于以下问题:C# Tenant.SetSiteAdmin方法的具体用法?C# Tenant.SetSiteAdmin怎么用?C# Tenant.SetSiteAdmin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tenant
的用法示例。
在下文中一共展示了Tenant.SetSiteAdmin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAdministratorsTenant
/// <summary>
/// Adds additional administrators to a site collection using the Tenant administration csom. See AddAdministrators for a method
/// that does not have a dependency on the Tenant administration csom.
/// </summary>
/// <param name="web">Site to be processed - can be root web or sub site</param>
/// <param name="adminLogins">Array of logins for the additional admins</param>
/// <param name="siteUrl">Url of the site to operate on</param>
public static void AddAdministratorsTenant(this Web web, String[] adminLogins, Uri siteUrl)
{
Tenant tenant = new Tenant(web.Context);
foreach (var admin in adminLogins)
{
tenant.SetSiteAdmin(siteUrl.ToString(), admin, true);
var spAdmin = web.EnsureUser(admin);
web.AssociatedOwnerGroup.Users.AddUser(spAdmin);
web.AssociatedOwnerGroup.Update();
web.Context.ExecuteQuery();
}
}
示例2: AddAdministratorsTenant
/// <summary>
/// Add a site collection administrator to a site collection
/// </summary>
/// <param name="web">Site to operate on</param>
/// <param name="adminLogins">Array of admins loginnames to add</param>
/// <param name="siteUrl">Url of the site to operate on</param>
/// <param name="addToOwnersGroup">Optionally the added admins can also be added to the Site owners group</param>
public static void AddAdministratorsTenant(this Web web, IEnumerable<UserEntity> adminLogins, Uri siteUrl, bool addToOwnersGroup = false)
{
if (adminLogins == null)
throw new ArgumentNullException("adminLogins");
if (siteUrl == null)
throw new ArgumentNullException("siteUrl");
Tenant tenant = new Tenant(web.Context);
foreach (UserEntity admin in adminLogins)
{
var siteUrlString = siteUrl.ToString();
tenant.SetSiteAdmin(siteUrlString, admin.LoginName, true);
var spAdmin = web.EnsureUser(admin.LoginName);
if (addToOwnersGroup)
{
web.AssociatedOwnerGroup.Users.AddUser(spAdmin);
web.AssociatedOwnerGroup.Update();
}
web.Context.ExecuteQuery();
}
}