zaterdag 5 november 2011

Get Permissions info of a List or a Site


In this function fill's in a ArrayList with the some permission properties of 
users or usergroups of a Site or a List using the SharePoint Webservice Lists.asmx .  

    private void GetSPPermissions(string myurl, string mylist, string stype, ArrayList myAlist)
    {
        SetStatus("Initialize webservice...");
        myAlist.Clear();
        WS_Permissions.Permissions permissions = new WS_Permissions.Permissions();
        if (chk_DefaultLoggin.Checked)
            permissions.Credentials = System.Net.CredentialCache.DefaultCredentials;
        else
        {
            permissions.PreAuthenticate = true;
            permissions.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text);
        }
        permissions.Url = myurl + @"/_vti_bin/permissions.asmx";
        try
        {
   // stype can contain Web or List depending if mylist contains a listname or a sitename
            XmlNode myNode = permissions.GetPermissionCollection(mylist, stype);
            XmlNodeList pnodes = myNode.SelectNodes("*");
            foreach (XmlNode pnode in pnodes)
            {
                foreach (XmlNode node in pnode)
                {
                    ArrayList userList = new ArrayList();
                    string mId = node.Attributes["MemberID"].Value;
                    string mMask = node.Attributes["Mask"].Value;
                    string mIsUser = node.Attributes["MemberIsUser"].Value;
                    
                    string mRoleName = "";
                    string mUserLogin = "";
                    if (mIsUser.ToLower().Equals("true"))
                    {
                        mUserLogin = node.Attributes["UserLogin"].Value;
                    }
                    else
                    {
                        mRoleName = node.Attributes["GroupName"].Value;
                    }
                    string mGlobal = node.Attributes["MemberGlobal"].Value;
                    string mName = "";
                    if (mIsUser.Equals("False"))
                        mName = mRoleName;
                    else
                        mName = mUserLogin;
                    userList.Add(mName);
                    userList.Add(mIsUser);
                    userList.Add(mRoleName);
                    userList.Add(mGlobal);
                    myAlist.Add(userList);
                }
            }
        }
        catch (Exception exception1)
        {
            MessageBox.Show(exception1.Message, "Error loading Permissions info", MessageBoxButtons.OK);
            this.SetStatus("Error loading Permissions info");
         }
        finally
        {
            permissions.Dispose();
        }
    }

 

Geen opmerkingen:

Een reactie posten