It uses the UserGroup web service to list all the SharePoint Groups a user belongs to in a specified Site Collection
using System;
using System.IO;
using System.Xml;
using ListUsersGroups.ug;
namespace ListUsersGroups
{
class Program
{
static int Main(string[] args)
{
if (args.Length < 2)
return help();
try
{
UserGroup usergroup = new UserGroup();
usergroup.UseDefaultCredentials = true;
usergroup.Url = args[0]+"/_vti_bin/usergroup.asmx";
XmlNode groupXml =usergroup.GetGroupCollectionFromUser(args[1]);
XmlDocument doc = new XmlDocument();
doc.Load(new XmlNodeReader(groupXml));
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/directory/");
foreach (XmlNode group in doc.SelectNodes("//sp:Groups/sp:Group", nsmgr))
Console.WriteLine(group.Attributes["Name"].Value);
}
catch (Exception ex)
{
Console.WriteLine("{0}\r\n{1}", ex.Message, ex.StackTrace);
}
return 0;
}
private static int help()
{
Console.WriteLine(@"{0} ", Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]));
Console.WriteLine(@" Site-url: Url of site collection including protocol (example http://localhost)");
Console.WriteLine(@" username: Full username including domain (example MOSSWORK\user)");
return -1;
}
}
}