2014-09-03 45 views
5

bir grup oluşturmak ve grup sahibi ve aşağıdaki kodları kullanabilirsiniz varsayılan kullanıcı eklemek isterseniz:Bir SharePoint grubu, İstemci Nesne Modeli ile Grup Sahibi olarak nasıl eklenir?

string siteUrl = "https://server/sites/sitename"; 
ClientContext clientContext = new ClientContext(siteUrl); 
Web web = clientContext.Web; 

GroupCreationInformation groupCreationInfo = new GroupCreationInformation(); 
groupCreationInfo.Title = "Custom Group"; 
groupCreationInfo.Description = "description ..."; 

User owner = web.EnsureUser(@"domain\username1");  
User member = web.EnsureUser(@"domain\username2"); 

Group group = web.SiteGroups.Add(groupCreationInfo);  
group.Owner = owner;    
group.Users.AddUser(member);  
group.Update(); 

clientContext.ExecuteQuery(); 

Sorum şu: Ben Grubu Sahibi olarak bir kullanıcı eklemek nasıl biliyorum ama eklemek isterseniz Grup sahibi olarak bir SharePoint grubu "Teknik Destek", kodun ne olması gerektiği?

cevap

6

kullanın GroupCollection.GetByName veya GroupCollection.GetById yöntem sitesinden mevcut bir grubu almak ve daha sonra örneğin, onun değerine Group.Owner property ayarlamak için:

using (var ctx = new ClientContext(webUri)) 
{ 
    ctx.Credentials = credentials; 

    var groupCreationInfo = new GroupCreationInformation 
    { 
     Title = groupName, 
     Description = groupDesc 
    }; 

    var groupOwner = ctx.Web.SiteGroups.GetByName("Tech Support"); //get an existing group 

    var group = ctx.Web.SiteGroups.Add(groupCreationInfo); 
    group.Owner = groupOwner; 
    group.Update(); 
    ctx.ExecuteQuery();  
} 
+0

teşekkürler Vadim. GetById() çalıştım çalıştı. GetByName() çalışmayı denedim, bu yüzden VS 2010 yılında denedim çünkü sanırım. Bunu VS 2013 sonra deneyeceğim. Ama bence bu çözüm. – allan8964

+0

Doğru, GroupCollection.GetByName, SharePoint 2013 CSOM API –

+0

'da tanıtıldı GetByName(), VS 2013'te çalıştı. Tekrar teşekkürler! – allan8964

İlgili konular