1
votes

I want to enumerate all of the Groups in my SharePoint 2010 site using Visual Studio 2010 and C#. I don't want to create anything that needs to be deployed unless it's absolutely necessary. Is there a way to, basically, connect to the SharePoint instance and interrogate it for Groups and other objects without deploying anything?

Please don't respond with a PowerShell script. I want to do this using Visual Studio and C#.

Thanks,
Doug

1

1 Answers

1
votes

Using the SharePoint 2010 Client Object Model (2010 & 2013) you can write something like this:

static void Main(string[] args)
{
    var ctx = new ClientContext("http://server");
    ctx.Credentials = new System.Net.NetworkCredential("username", "password", "domain");

    ctx.Load(ctx.Web.SiteGroups);
    ctx.ExecuteQuery();

    foreach (Group g in ctx.Web.SiteGroups)
    {
        Console.WriteLine(g.LoginName);
    }
}