Notes Field Not Getting Populated by SPUserCollection.Add Method
So here is the deal:
You add a user to the users collection of a site collection by calling into the SPUserCollection.Add method passing login name, email, name and notes as parameters, but notes field doesn’t get populated as you expected:
[CSharp]
using (SPSite site = new SPSite(url))
{
using (SPWeb sweb = site.OpenWeb())
{
//Ommitted Code for brevity
sweb.SiteUsers.Add(“foo\\JohnDoe”, “JohnDoe@foo.com”, “John Doe”, “Is it John Doe or John Dough?”);
//Ommitted Code for brevity
}
}
[/CSharp]
Although, using the code snippet above, the user is added correctly to the user collection of the site but notes field is always left blank. Note that in the above code, I am just adding the user to the users collection and I don’t bother adding him to any specific group at this point (for example by calling into SPWeb.Groups[groupName].AddUser). Let’s suppose that my requirement only dictates to add the user to this collection at this point and that’s all for now.
kept at each site collection level, there is this hidden list called ‘User Information List’ that stores some metadata about every and each user has ever browsed, authenticated or added to a group in that site collection .
[CSharp]
using (SPSite site = new SPSite(url))
{
using (SPWeb sweb = site.OpenWeb())
{
//Ommitted Code for brevity
sweb.SiteUsers.Add(“foo\\JohnDoe”, “JohnDoe@foo.com”, “John Doe”,string.Empty);
user = sweb.AllUsers[“foo\\JohnDoe”];
SPList list = sweb.Lists[“User Information List”];
SPListItem userItem = list.Items.GetItemById(user.ID);
userItem[“Notes”] = “Is it John Doe or John Dough?”;
userItem.Update();
//Ommitted Code for brevity
}
}
[/CSharp]
This way you pass an empty string to the calling method (SiteUsers.Add) and update the Notes field in a separate call.