How to update ‘tp_title’ field of the UserInfo table of the SharePoint’s Content Database from the OM code?


Last week, I got this fascinating requirement. The requirement was to update the 'tp_title' field of the UserInfo table using OM Code API's. As we all SharePoint guys know that any query to the content database (even a select query, as it can affect the indexes) can put you in unsupported scenario with PSS guys.

So the only savior would be through OM code. Checking the table and the values in the table I found that the value can be easily set through the SPUser's name property. So the easy code piece for this would be:-

string strSiteCollectionUrl = "http://abc:1234"; //change it to your SiteCollectionUrl
SPSite site = new SPSite(strSiteCollectionUrl);
SPWeb web = site.OpenWeb();
SPUserCollection userColl = web.Users;
string strLoginName = @"XXX\qz19g4";
string newTitleName = "XXXX VVV- qz10g4";
SPUser user = userColl[strLoginName];
user.Name = strTitleName;
user.Update();


Comments (4)

  1. AJ_FLORIDA says:

    Great Blog this code has really helped me solve a problem I was working on.  Just a heads up, you have a variable named newTitleName but when you go to update you call strTitleName.  The other thing I noticed is you are not using the dispose method for your site or web.  I was told to always use that or a using statement. Here is the code I used, please let me know if I am doing this wrong.                      using (SPSite site = new SPSite(strSiteCollectionUrl))

                       {

                           site.AllowUnsafeUpdates = true;

                           using (SPWeb web = site.OpenWeb())

                           {

                               web.AllowUnsafeUpdates = true;

                               SPUser user = web.AllUsers[domainName];

                               user.Name = newDisplayName;

                               user.Update();

                               user = null;

                            }

                       }

  2. Hi AJ,

    Thanks for pointing the error regarding variable name – strTitleName. You are correct it should be newTitleName.

    And regarding the Disposing of SPWeb and SPsite objects, you have done it the right way.

    Cheers,

    Varun

  3. RoyJoyson says:

    Thanks for the details. Does it update the userinfo table at site collection level?

    Regards

    Roy Joyson

Skip to main content