2014-03-25 72 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。更多關注...

相關問題