{"id":802,"date":"2009-02-23T14:40:30","date_gmt":"2009-02-23T19:40:30","guid":{"rendered":"http:\/\/blogs.devhorizon.com\/reza\/?p=802"},"modified":"2009-02-23T14:40:30","modified_gmt":"2009-02-23T19:40:30","slug":"notes-field-not-getting-populated-by-spusercollectionadd-method","status":"publish","type":"post","link":"https:\/\/blogs.devhorizon.com\/reza\/2009\/02\/23\/notes-field-not-getting-populated-by-spusercollectionadd-method\/","title":{"rendered":"Notes Field Not Getting Populated by SPUserCollection.Add Method"},"content":{"rendered":"<p>So here is the deal:<\/p>\n<p>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&#8217;t get populated as you expected:<\/p>\n<p>[CSharp]<br \/>\nusing (SPSite site = new SPSite(url))<br \/>\n{<br \/>\n  using (SPWeb sweb = site.OpenWeb())<br \/>\n  {<br \/>\n     \/\/Ommitted Code for brevity<br \/>\n     sweb.SiteUsers.Add(&#8220;foo\\\\JohnDoe&#8221;, &#8220;JohnDoe@foo.com&#8221;, &#8220;John Doe&#8221;, &#8220;Is it John Doe or John Dough?&#8221;);<br \/>\n    \/\/Ommitted Code for brevity<br \/>\n  }<br \/>\n}<br \/>\n[\/CSharp]<\/p>\n<p>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&#8217;t bother adding him to any specific group at this point (for example by calling into SPWeb.Groups[groupName].AddUser). Let&#8217;s suppose that my requirement only dictates to add the user to this collection at this point and that&#8217;s all for now.<\/p>\n<p>kept at each site collection level, there is this hidden list called \u2018User Information List\u2019 that stores some metadata about every and each user has ever browsed, authenticated or added to a group in that site collection . <rant>This design decision along with many other things kept at the site collection level gives countless developers a good amount of grief and frustration as you may be aware of <\/rant>. When a user is granted access to a site, a new list item will be created in that list. The User Information List can be accessed via the browser by navigating to \/_catalogs\/users\/simple.aspx from your site or via Object model , only if you or your code runs under sufficient privileges.  So, we can use that list for troubleshooting above issue by updating the &#8216;Notes&#8217; field after the user is added. The following example shows how to interact with this list for setting the required user properties.<\/p>\n<p>[CSharp]<br \/>\nusing (SPSite site = new SPSite(url))<br \/>\n{<br \/>\n  using (SPWeb sweb = site.OpenWeb())<br \/>\n  {<br \/>\n     \/\/Ommitted Code for brevity<br \/>\n     sweb.SiteUsers.Add(&#8220;foo\\\\JohnDoe&#8221;, &#8220;JohnDoe@foo.com&#8221;, &#8220;John Doe&#8221;,string.Empty);<br \/>\n     user = sweb.AllUsers[&#8220;foo\\\\JohnDoe&#8221;];<br \/>\n     SPList list = sweb.Lists[&#8220;User Information List&#8221;];<br \/>\n     SPListItem userItem = list.Items.GetItemById(user.ID);<br \/>\n     userItem[&#8220;Notes&#8221;] = &#8220;Is it John Doe or John Dough?&#8221;;<br \/>\n     userItem.Update();<br \/>\n     \/\/Ommitted Code for brevity<br \/>\n  }<br \/>\n}<br \/>\n[\/CSharp]<\/p>\n<p>This way you pass an empty string to the calling method (SiteUsers.Add) and update the Notes field in a separate call. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t get populated as you expected: [CSharp] using (SPSite site = new SPSite(url)) { using (SPWeb sweb = site.OpenWeb()) { [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-802","post","type-post","status-publish","format-standard","hentry","category-moss-2007"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Notes Field Not Getting Populated by SPUserCollection.Add Method - Reza Alirezaei&#039;s Blog %<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blogs.devhorizon.com\/reza\/2009\/02\/23\/notes-field-not-getting-populated-by-spusercollectionadd-method\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Reza Alirezaei\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2009\\\/02\\\/23\\\/notes-field-not-getting-populated-by-spusercollectionadd-method\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2009\\\/02\\\/23\\\/notes-field-not-getting-populated-by-spusercollectionadd-method\\\/\"},\"author\":{\"name\":\"Reza Alirezaei\",\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/#\\\/schema\\\/person\\\/cdbb24d283697a65951cb4a14e474938\"},\"headline\":\"Notes Field Not Getting Populated by SPUserCollection.Add Method\",\"datePublished\":\"2009-02-23T19:40:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2009\\\/02\\\/23\\\/notes-field-not-getting-populated-by-spusercollectionadd-method\\\/\"},\"wordCount\":419,\"commentCount\":1,\"articleSection\":[\"MOSS 2007\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2009\\\/02\\\/23\\\/notes-field-not-getting-populated-by-spusercollectionadd-method\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2009\\\/02\\\/23\\\/notes-field-not-getting-populated-by-spusercollectionadd-method\\\/\",\"url\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2009\\\/02\\\/23\\\/notes-field-not-getting-populated-by-spusercollectionadd-method\\\/\",\"name\":\"Notes Field Not Getting Populated by SPUserCollection.Add Method - Reza Alirezaei's Blog %\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/#website\"},\"datePublished\":\"2009-02-23T19:40:30+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/#\\\/schema\\\/person\\\/cdbb24d283697a65951cb4a14e474938\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2009\\\/02\\\/23\\\/notes-field-not-getting-populated-by-spusercollectionadd-method\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/#website\",\"url\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/\",\"name\":\"Reza Alirezaei's Blog\",\"description\":\"Blogging from the field!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/#\\\/schema\\\/person\\\/cdbb24d283697a65951cb4a14e474938\",\"name\":\"Reza Alirezaei\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g\",\"caption\":\"Reza Alirezaei\"},\"url\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/author\\\/rezaa\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Notes Field Not Getting Populated by SPUserCollection.Add Method - Reza Alirezaei's Blog %","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blogs.devhorizon.com\/reza\/2009\/02\/23\/notes-field-not-getting-populated-by-spusercollectionadd-method\/","twitter_misc":{"Written by":"Reza Alirezaei","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blogs.devhorizon.com\/reza\/2009\/02\/23\/notes-field-not-getting-populated-by-spusercollectionadd-method\/#article","isPartOf":{"@id":"https:\/\/blogs.devhorizon.com\/reza\/2009\/02\/23\/notes-field-not-getting-populated-by-spusercollectionadd-method\/"},"author":{"name":"Reza Alirezaei","@id":"https:\/\/blogs.devhorizon.com\/reza\/#\/schema\/person\/cdbb24d283697a65951cb4a14e474938"},"headline":"Notes Field Not Getting Populated by SPUserCollection.Add Method","datePublished":"2009-02-23T19:40:30+00:00","mainEntityOfPage":{"@id":"https:\/\/blogs.devhorizon.com\/reza\/2009\/02\/23\/notes-field-not-getting-populated-by-spusercollectionadd-method\/"},"wordCount":419,"commentCount":1,"articleSection":["MOSS 2007"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blogs.devhorizon.com\/reza\/2009\/02\/23\/notes-field-not-getting-populated-by-spusercollectionadd-method\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blogs.devhorizon.com\/reza\/2009\/02\/23\/notes-field-not-getting-populated-by-spusercollectionadd-method\/","url":"https:\/\/blogs.devhorizon.com\/reza\/2009\/02\/23\/notes-field-not-getting-populated-by-spusercollectionadd-method\/","name":"Notes Field Not Getting Populated by SPUserCollection.Add Method - Reza Alirezaei's Blog %","isPartOf":{"@id":"https:\/\/blogs.devhorizon.com\/reza\/#website"},"datePublished":"2009-02-23T19:40:30+00:00","author":{"@id":"https:\/\/blogs.devhorizon.com\/reza\/#\/schema\/person\/cdbb24d283697a65951cb4a14e474938"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blogs.devhorizon.com\/reza\/2009\/02\/23\/notes-field-not-getting-populated-by-spusercollectionadd-method\/"]}]},{"@type":"WebSite","@id":"https:\/\/blogs.devhorizon.com\/reza\/#website","url":"https:\/\/blogs.devhorizon.com\/reza\/","name":"Reza Alirezaei's Blog","description":"Blogging from the field!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blogs.devhorizon.com\/reza\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blogs.devhorizon.com\/reza\/#\/schema\/person\/cdbb24d283697a65951cb4a14e474938","name":"Reza Alirezaei","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g","caption":"Reza Alirezaei"},"url":"https:\/\/blogs.devhorizon.com\/reza\/author\/rezaa\/"}]}},"_links":{"self":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/comments?post=802"}],"version-history":[{"count":0,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/802\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/media?parent=802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/categories?post=802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/tags?post=802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}