Date: 
Monday, July 20, 2009
Title: List all SharePoint groups a user belongs to
This is just a small Utility requested on one of the SharePoint Newsgroups It uses the UserGroup web service to list all the SharePoint Groups a user belongs to in a specified Site Collection It's a small console application which requires two parameters: ···The first parameter is the Url of the site collection including protocol (example: http://localhost) ···The second parameter is the full username including Domain (example: MOSSWORK\user)
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;
}
}
}
This execuable can be found here and the source code here
|
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent
my employer's view in any way. And all information or programs are without warranty. Use at your own risk
© Copyright 2013 
Per Jakobsen
|
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|
| 28 | 29 | 30 | 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 | 1 |
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
Navigation
Categories