zaterdag 5 november 2011

How to get the list of users defined in a SharePoint Group


This is an example of how you can receive the users of a SharePoint Group using the SharePoint 
Webservice UserGroup.asmx and put the result in a ArrayList.  

private void GetUserOfGroup(string myurl,string sUGroup, ArrayList myAlist)
    {
        SetStatus("Initialize webservice...");
        WS_UserGroup.UserGroup usergroup = new WS_UserGroup.UserGroup();
        if (chk_DefaultLoggin.Checked)
            usergroup.Credentials = System.Net.CredentialCache.DefaultCredentials;
        else
        {
            usergroup.PreAuthenticate = true;
            usergroup.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text);
        }
        usergroup.Url = myurl + @"/_vti_bin/usergroup.asmx";

        try
        {
            this.SetStatus("Getting Users for group " + sUGroup);
            XmlNode myNode = usergroup.GetUserCollectionFromGroup(sUGroup);
            XmlNodeList unodes = myNode.SelectNodes("*");
            foreach (XmlNode pnode in unodes)
            {
                foreach (XmlNode node in pnode)
                {
                    ArrayList mAList = new ArrayList();
                    string mName = node.Attributes["Name"].Value;
                    string mLoginName = node.Attributes["LoginName"].Value;
                    string mEmail = node.Attributes["Email"].Value;
                    string mSiteAdmin = node.Attributes["IsSiteAdmin"].Value;
                    string mDomainGroup = node.Attributes["IsDomainGroup"].Value;
                    mAList.Add(sUGroup);
                    mAList.Add(mName);
                    mAList.Add(mLoginName);
                    mAList.Add(mEmail);
                    mAList.Add(mSiteAdmin);
                    mAList.Add(mDomainGroup);
         myAlist.Add(mAList);
                }
            }

        }
        catch (Exception exception1)
        {
            MessageBox.Show(exception1.Message, "Error loading GetUsersOfGroup ", MessageBoxButtons.OK);
            this.SetStatus("Error loading GetUsersOfGroup ");
        }
        finally
        {
            usergroup.Dispose();
        }
        this.SetStatus("");
    }

Geen opmerkingen:

Een reactie posten