gpt4 book ai didi

c# - 如何模拟管理员用户创建 OneDrive 或个人网站?

转载 作者:太空宇宙 更新时间:2023-11-03 15:57:59 28 4
gpt4 key购买 nike

我正在使用 csom 在 office 365 中创建个人网站,如下所示

private void createPersonalSite()
{
try
{
//using (SPSite site = new SPSite("Site URL"))
//{
//SPServiceContext context = SPServiceContext.GetContext(site);
var targetSite = new Uri("https://test/sites/18thFeb");
var securePassword = new SecureString();
foreach (char c in adminPassword)
securePassword.AppendChar(c);

adminUserId = "yogesh@test.com";
var onlineCredentials = new SharePointOnlineCredentials(adminUserId, securePassword);

ClientContext clientContext = new ClientContext("https://test/sites/18thFeb");
clientContext.Credentials = onlineCredentials;

//Get user profile
//// Get the PeopleManager object and then get the target user's properties.
//Microsoft.SharePoint.Client.UserProfiles.PeopleManager peopleManager = new Microsoft.SharePoint.Client.UserProfiles.PeopleManager(clientContext);
//Microsoft.SharePoint.Client.UserProfiles.PersonProperties personProperties = peopleManager.GetPropertiesFor("domainName\\userName");

//personProperties.UserProfileProperties.

Microsoft.SharePoint.Client.UserProfiles.ProfileLoader loader = Microsoft.SharePoint.Client.UserProfiles.ProfileLoader.GetProfileLoader(clientContext);
Microsoft.SharePoint.Client.UserProfiles.UserProfile profile = loader.GetUserProfile();

Microsoft.SharePoint.Client.Site personalSite = profile.PersonalSite;

clientContext.Load(personalSite);
clientContext.ExecuteQuery();

// Let's check if the site already exists
if (personalSite.ServerObjectIsNull.Value)
{
// Let's queue the personal site creation using oob timer job based approach
// Using async mode, since end user could go away from browser, you could do this using oob web part as well
profile.CreatePersonalSiteEnque(true);
//clientContext.ExecuteQuery();
}

}
catch
{
int a = 10;
}
}

以上代码对用户 yogesh 有效,但对其他人无效。 Yogesh 能够创建我的网站。只有 yogesh 拥有管理员权限。我想通过使用 yogesh 凭证为所有用户创建我的网站。有什么办法吗?您能否提供我可以解决上述问题的任何代码或链接?

最佳答案

您需要将管理员帐户设置为 SiteCollectionAdminstrator。在 PowerShell 中,它看起来像这样:

Set-SPOUser -Site $fullPath -LoginName $o365login -IsSiteCollectionAdmin $true

来源:梭子鱼 OneDrive 权限设置指南:https://techlib.barracuda.com/bbs/onedriveadminpermissions

编辑:我还没有找到不需要目标用户密码的 C# 解决方案,因此我将封装 Set-SPOUser PowerShell cmdlet。更多精彩……

关于c# - 如何模拟管理员用户创建 OneDrive 或个人网站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22631254/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com