2014-03-25 34 views
2

我在办公室365创建的个人网站使用CSOM如下如何模拟管理员用户创建OneDrive或个人网站?

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 = "[email protected]"; 
       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凭证为所有用户创建我的网站。有没有办法做到这一点?你能否给我提供任何可以解决上述问题的代码或链接?

回答

0

您需要将admin帐户设置为SiteCollectionAdminstrator。在PowerShell中,它应该是这样的:

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

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

编辑:我还没有发现C#的解决方案不要求目标用户的密码,所以我打算包装Set-SPOUser PowerShell cmdlet。更多关注...

相关问题