none
get the group id by pasisng groupname csom sp 2010 RRS feed

  • Question

  • Hi all,

    I want to get the group id by passing the groupname in sharepoint 2010 csom.I dont have option to pass groupname using context.web.sitegroups.getbyname in sharepoint 2010 csom.please help me on this.

    Thanks in advance.

    regards,

    Praveen

    Thursday, February 7, 2019 9:18 AM

Answers

  • Hi,

    Modified the code snippet like this:

                ClientContext ctx = new ClientContext("http://sp/sites/team/");
                 Web oweb = ctx.Web;
                ctx.Load(oweb.SiteGroups);
                ctx.ExecuteQuery();
                ctx.Load(oweb.SiteGroups, groupitems => groupitems.Include(groupitem => groupitem.Title,
                  groupitem => groupitem.Id).Where(groupitem => groupitem.Title == "testgroup"));
                ctx.ExecuteQuery();
                Console.WriteLine(oweb.SiteGroups[0].Id);
                Console.WriteLine(oweb.SiteGroups[0].Title);

    Directly filter with Linq in ctx.Load() method.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Praveenrangu Friday, February 8, 2019 1:04 PM
    Friday, February 8, 2019 8:56 AM

All replies

  • Can we see your code?

    Thursday, February 7, 2019 9:53 AM
  • iam using below  linq query but i dont know how to return the result.

    public static void GetGroup()
     {
          using (ClientContext site = new ClientContext("http://dsdsd"))
          {
    
            
    
              var result = from g in site.Web.SiteGroups.OfType<Group>() where g.Title.Equals("testgroup") select g;
    
    
            
    
          }
    
    }

    Thursday, February 7, 2019 11:09 AM
  • Hi,

    Sample code for your reference:

               ClientContext ctx = new ClientContext("http://sp/sites/dev/");
                Web oweb = ctx.Web;
                ctx.Load(oweb.SiteGroups);
                ctx.ExecuteQuery();
                Group group = oweb.SiteGroups.GetByName("testgroup");
                ctx.Load(group, a => a.Id);
                ctx.ExecuteQuery();
                Console.WriteLine(group.Id);

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, February 8, 2019 2:09 AM
  • thanks for your reply iam using sharepoint 2010 i dont have property groups.getbyname.Please suggest how to implement using linq.
    Friday, February 8, 2019 8:36 AM
  • Hi,

    Modified the code snippet like this:

                ClientContext ctx = new ClientContext("http://sp/sites/team/");
                 Web oweb = ctx.Web;
                ctx.Load(oweb.SiteGroups);
                ctx.ExecuteQuery();
                ctx.Load(oweb.SiteGroups, groupitems => groupitems.Include(groupitem => groupitem.Title,
                  groupitem => groupitem.Id).Where(groupitem => groupitem.Title == "testgroup"));
                ctx.ExecuteQuery();
                Console.WriteLine(oweb.SiteGroups[0].Id);
                Console.WriteLine(oweb.SiteGroups[0].Title);

    Directly filter with Linq in ctx.Load() method.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Praveenrangu Friday, February 8, 2019 1:04 PM
    Friday, February 8, 2019 8:56 AM