So, in the previous posts we’ve looked at how to resolve a MembershipGroupId for a group (or at least, one way of doing so), and how to list users. Now, how do we add new users to our group?
Well, on our ‘list of users’ page, I have what looks like a a SharePoint toolbar. It’s actually just a table cunningly formatted to look like a toolbar, and the ‘Add users’ link on it is a LinkButton. In the codebehind it’s click event is:
protected void BtnAddUsersToGroup_Click(object sender, EventArgs e)
int iGroup = (int)ViewState[GROUP];
SPUtility.Redirect("SimpleUG/AddUsers.aspx?MembershipGroupId=" + iGroup, SPRedirectFlags.RelativeToLayoutsPage, this.Context);
So, all we’re doing is going to a page called ‘AddUsers’ and passing the MembershipGroupId again. Continue reading “How I simplified the Users and Group UI – Adding Users” →
I needed to query an SPList by a User column. I wanted to query the list by account (DOMAINUser) and check that that user existed. Essentially, I’m validating the input of a PeopleEditor control against users in the SPList. Unfortunately, this didn’t look possible – examining my list items through the object model I seemed to get back a value like a lookup field – that is [number;#value]. For example:
Not very useful – accounts are unique, but John Smith’s aren’t. I was beginning to feel a bit frantic about not being able to do this sort of query when I found this very useful post by Karthikeyan Kasiviswanathan. The short of it – you have to set the column up to display the account if you want to query by the account.
Sort of makes sense – but is a bit weird too. I mean, isn’t the account the unique bit? Shouldn’t I always be able to query by that? Still, this should work for me.
Something I didn’t know about – the people picker shows disabled user accounts – and ‘Tales from the field’ has a solution (on a per web app basis). Just in case the blog ever goes down:
This default behavior can be changed on a per web application basis to return only enabled user accounts. In the example below I have configured this for the web application http://moss using stsadm. This command configures MOSS 2007 to use a custom LDAP query.
stsadm -o setproperty -pn peoplepicker-searchadcustomfilter -url http://moss -pv (!userAccountControl=514)
If you are interested in putting together more granular filters I strongly recommend the following guide on LDAP, LDAP Query Basics – http://technet.microsoft.com/en-us/library/aa996205(EXCHG.65).aspx
Nice one Brendan