In my current project I wanted to create a webpart where I could add users to a certain group in a site from a single adminstration site. Furthermore I wanted to use the nice and elegant People Picker. This control is called “PeopleEditor” which belongs to the Microsoft.SharePoint.WebControls namespace. This is how it looks like when ran in a webpart :
Here is the code to get the values from the control :
PeopleEditor _peoplePicker = new PeopleEditor();
_peoplePicker.AllowTypeIn = true;
_peoplePicker.AllowEmpty = false;
_peoplePicker.MultiSelect = false;
SPWeb web = new SPSite("urlToWeb").OpenWeb();
SPGroup group = web.SiteGroups["groupname"];
web.AllowUnsafeUpdates = true;
if (Group.Users.Count > 0)
{
SPUserCollection users = group.Users;
foreach (SPUser user in users)
{
group.Users.Remove(user.LoginName);
group.Update();
}
}
try
{
group.AddUser(_peoplePicker.Accounts[0].ToString(), "", "", "");
group.Update();
}
catch (ArgumentException error)
{
//Do ErrorHandling here
}
finally
{
web.AllowUnsafeUpdates = false;
web.Close();
web.Dispose();
}
And here is the code to set the values from the control :
if (group.Users.Count > 0)
{
foreach (SPUser user in group.Users)
{
_peoplePicker.CommaSeparatedAccounts= user.LoginName;
}
}
Took me a couple of hours to find out I had to use the CommaSeperatedAccount property. Since you are getting the values using the Accounts or the Entities properties, it seems a bit odd to use this method to set the values.
5 Comments
|
Posted June 17, 2008 - 14:57
by Robin Meure
in
<Update>SharePoint is very slowly the first time because it compiles all the libraries and after that they are cached. SharePoint is extremely slowly if this is done on a system which has no internet access because something else occurs during compilation! When I read the article about How to Optimize a SharePoint Server 2007 Web Content Management Site for Performance I stumbled upon a comment from Jeroen Ritmeijer who did some investigation upon the slow load times. Here is his comment and a link on what’s really going on: </Update>
Ever since SharePoint 2007 was introduced I have been really disappointed with the 2 minute spin-up time of the sites and the 30 second wait when launching STSADM.
As it turns out this problem does not occur on all SharePoint installations, it only happens under a certain combination of circumstances. Fortunately I have identified the root cause as well as a solution.
Some symptoms:
STSADM:
* You start STSADM without any parameters
* There is a delay of about 30 seconds
* There is no CPU activity, swapping or significant network traffic.
SharePoint web requests
* You recycle the app pool / perform an IISRESET.
* Request a SharePoint page
* There is a delay of about 2 minutes
* There is no CPU activity, swapping or significant network traffic.
After quite some investigation I have found that this is related to CRL (Certificate Revocation List) lookups when assemblies are being loaded. I have added a list of possible workarounds to the following blog posting:
http://jritmeijer.spaces.live.com/blog/cns!8A48A27460FB898A!965.entry
Thanks Jeroen ;)
2 Comments
|
Posted June 5, 2008 - 12:44
by Robin Meure
in
Just like you cannot live without U2U’s CAML Query builder, you also cannot live without MOSS SQL SearchCoder! Developed by my mate Daniel, comes this tool that lets you write your custom search queries in a really easy way. See the following screenshot on how easy it is..
Brilliant stuff eh? Go get it from CodePlex and let us know what you think of it and how we (well.. actually only Daniel..) can improve it :)
2 Comments
|
Posted June 4, 2008 - 19:32
by Robin Meure
in