none
Get all Users from SharePoint group based on Domain name using server object model RRS feed

  • Question

  • hi,

    I want to retrieve users from specific sharepoint group based on domain name.

    For example the current logged in user domain is abc then i want to retrieve only abc domain users from the specific sharepoint group.If the domain is def the only def domain users from sharepoint group 

    I prefer server object model but if not possible please provide some example with other approach.

    Regards,

    Poovi

    Wednesday, February 15, 2017 7:21 AM

All replies

  • Hi Poovi,

    The following code snippet for your reference:

    using (SPSite site = new SPSite("http://sp13"))
    {
    	using (SPWeb web = site.OpenWeb())
    	{
    
    		SPGroup group = web.Groups.GetByName("your group name");
    
    		foreach(SPUser user in group.Users)
    		{
    			if (user.LoginName.Split('\\')[0].Contains("your domain name"))
    			{
    				Console.WriteLine("User Name:"+user.Name);
    			}
    		}
    		Console.ReadKey();                   
    	}
    }

    Best Regards,

    Dennis


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

    Thursday, February 16, 2017 3:34 AM
    Moderator
  • Hi Poovi,

    Any update?

    If the reply help you, please mark the reply as answer, it will make others who stuck with the similar issue easier to search for valid solutions in this forum.

    Best regards,
    Dennis


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


    Thursday, March 9, 2017 10:15 AM
    Moderator