Get SharePoint Groups a user is member of using SharePoint Client Object Model(silverlight & web service)
Get SharePoint Groups a user is member of using SharePoint Client Object Model(silverlight & web service)
- Here i will explain how to get all groups for a specific user(who is member of those group) using silverlight and web service.
- In this code we are calling GetGroupCollectionFromUserAsync web method of the SharePoint UserGroup.asmx web service.
- You can see all kind of methods by typing the following url in browser
http://<site url>/_vti_bin/UserGroup.asmx
Steps:
- For detiled steps see this link
- In your silverlight program add a service reference, and type the following url
http://<site url>/_vti_bin/UserGroup.asmx - Give a name(I gave as UGService)
- Add the following Code.
C# Code:
// Create a object of the UserGroupSoapClient class
UGService.UserGroupSoapClient service = new UGService.UserGroupSoapClient();
// Define the Event handler method and Async event
service.GetGroupCollectionFromUserCompleted += new EventHandler<GetGroupCollectionFromUserCompletedEventArgs>(service_GetGroupCollectionFromUserCompleted);
service.GetGroupCollectionFromUserAsync(UserLoginName); //see this link to get user
service.GetGroupCollectionFromUserCompleted += new EventHandler<GetGroupCollectionFromUserCompletedEventArgs>(service_GetGroupCollectionFromUserCompleted);
service.GetGroupCollectionFromUserAsync(UserLoginName); //see this link to get user
void service_GetGroupCollectionFromUserCompleted(object sender, GetGroupCollectionFromUserCompletedEventArgs e)
{
try
{
// e.Result will hold the xml with the User Groups returned by the web method
var eGroups = e.Result.Elements().Where(c => c.Name.LocalName == "Groups").First().Elements().Where(c => c.Name.LocalName == "Group").AsEnumerable();
foreach (XElement ele in eGroups)
{
string GroupName = ele.Attribute("Name").Value;
ComboBox1.Items.Add(GroupName);
}
}
catch (Exception ex)
{ MessageBox.Show(ex.Message.ToString()); }
}
{
try
{
// e.Result will hold the xml with the User Groups returned by the web method
var eGroups = e.Result.Elements().Where(c => c.Name.LocalName == "Groups").First().Elements().Where(c => c.Name.LocalName == "Group").AsEnumerable();
foreach (XElement ele in eGroups)
{
string GroupName = ele.Attribute("Name").Value;
ComboBox1.Items.Add(GroupName);
}
}
catch (Exception ex)
{ MessageBox.Show(ex.Message.ToString()); }
}
To get current user detail see this link for get current user
for more details Refer this link
Get Sharepoint Users using Silverlight and Web Service
for more details Refer this link
Get Sharepoint Users using Silverlight and Web Service
Comments
Post a Comment