Menu
Cutty
  • Chryslers
  • Lutherie
  • YLSNED
  • About
Cutty

Setting AssociatedMembersGroup using Client Object Model

Posted on May 5, 2013February 20, 2015 by Iain 'Cutty' Carlin

I had some code that set the AssociatedMembersGroup in SharePoint using the Client Object Model. For whatever reason (possibly a CU recently installed), the code below no longer works:

ClientContext lClientContext = new ClientContext(vSiteURL);
lClientContext.Credentials = new NetworkCredential(Utils.APP_USERNAME, Utils.APP_PASSWORD, Utils.APP_DOMAIN);
Web lWeb = lClientContext.Web;

lClientContext.Load(lWeb, website => website.AssociatedMemberGroup, website => website.SiteGroups);
lClientContext.ExecuteQuery();

foreach (Group lGroup in lWeb.SiteGroups)
{
if (lGroup.Title == vGroupName)
{
lWeb.AssociatedMemberGroup = lGroup;
lWeb.Update();
lClientContext.ExecuteQuery();
break;
}
}

I had to change to doing this inside my create group method:

 ClientContext lClientContext = new ClientContext(vSiteURL);
lClientContext.Credentials = new NetworkCredential(Utils.APP_USERNAME, Utils.APP_PASSWORD, Utils.APP_DOMAIN);
Web lWeb = lClientContext.Web;

GroupCreationInformation lGroupDef = new GroupCreationInformation();
lGroupDef.Title = pGroupName;
lGroupDef.Description = pDescription;

Group lNewGroup = lWeb.SiteGroups.Add(lGroupDef);

if (pSetAsDefault)
lWeb.AllProperties["vti_associatemembergroup"] = lNewGroup;

lNewGroup.Update();

That I found at: http://stackoverflow.com/questions/1437430/how-to-programmatically-determine-the-3-permission-groups-visitors-members-owner.

  • SharePoint
  • Recent Posts

    • Books I read in 2025
    • 2024 was the best year for our solar system
    • Books I read in 2024
    • Books I read in 2023
    • Happy New Year 2024

    Categories

    • Chryslers (1)
    • Cutty's Blog (13)
    • Lutherie (38)
    • You Learn Something New Every Day (44)
    ©2026 Cutty | Powered by Superb Themes