• SharePoint 2010 change order of User Profile properties

    by  • January 19, 2011 • SharePoint, Software • 10 Comments

    Creating a new user profile property is really easy in SharePoint and there are lots of articles out there that describe how to do it but once you have created the custom property you find that it appears at the bottom of the user profile page and changing the order of the properties is a PITA – you have to click the up arrow next to the property to move it up one and each time you click the arrow the page refreshes so you have to scroll back down before you can do it again and if you have to move the property by 50 positions that 50 clicks and 50 page refreshes – AAAAARGH!

    Fortunately you can do the same thing with some simple powershell:-

    Add-Type -Path "c:\program files\common files\microsoft shared\web server extensions\14\isapi\microsoft.office.server.dll"
    $mySiteUrl = "http://yourmysitegoeshere"
    $site = Get-SPSite $mySiteUrl
    $context = Get-SPServiceContext $site
    $upConfigManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($context)
    $profilePropertyManager = $upConfigManager.get_ProfilePropertyManager()
    $upConfigManager.GetProperties().SetDisplayOrderByPropertyName("NameOfProperty", OrderNumber)

    The powershell method is a much easier way to re-order things I’m sure you will agree :-)

    About

    10 Responses to SharePoint 2010 change order of User Profile properties

    1. claraoscura
      January 20, 2011 at 1:06 pm

      great! thanks

    2. Shukraj Khadse
      February 17, 2011 at 5:59 am

      I have written the c# code to make the order of the user profile Properties.

      Add the following referances to your project

      System.Web
      Microsoft.SharePoint.portal
      Microsoft.SharePoint
      Microsoft.Office.Server
      Microsoft.Office.Server.UserProfile

      c# code(here site url is the url of the central admin site)

      using (SPSite site = new SPSite(“http://sp2010unv:5000/”))
      {
      //ServerContext con = ServerContext.GetContext(site);
      SPServiceContext context = SPServiceContext.GetContext(site);
      UserProfileManager profileManager = new UserProfileManager(context);

      // get the properties
      // ProfileSubtypePropertyManager pc = ProfileSubtype;
      //serProfileManager profileManager = new UserProfileManager(context);
      UserProfileConfigManager manager = new UserProfileConfigManager(context);
      PropertyCollection pc = manager.GetProperties();
      // PropertyCollection pc = profileManager.Properties;
      pc.SetDisplayOrderByPropertyName(“UserCategory”, 1);
      pc.CommitDisplayOrder();

      //profileManager.CreateUserProfile(sAccount);

      //to set prop values on user profile
      //UserProfile u = profileManager.GetUserProfile(“Ankur”);
      //string sPropName = “honorfic”;
      //u[sPropName] = “male”;
      //u.Commit();

      Console.WriteLine(“Sucess”);
      Console.ReadLine();

      }

    3. Craig
      April 12, 2011 at 2:26 pm

      I am not able to get this working. Any thoughts on what I might be doing wrong? I run the script, get no errors, but the property doesn’t move. I am running it as the Farm Admin account.

    4. PaulE
      April 27, 2011 at 11:50 pm

      You must also call CommitDisplayOrder() on the PropertyCollection. After that, just a little bit of patience should do the trick (the change isn’t viewable immediately in Manage User Properties).

    5. JarnoL
      August 24, 2011 at 11:35 am

      Hi and thanks for the script!

      I’m getting a NullReferenceException when creating the UserProfileConfigManager: $upConfigManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($context). I’m running this with a Farm Administrator Account.

      I was wondering if you had any ideas?

    6. JarnoL
      August 24, 2011 at 1:22 pm

      Ok I had to run this using a farm account, not an administrator account. Makes sense, since the admin probably doesn’t have access to the database, and the direct om api probably assums that you’re running as farm.

    7. AmolK
      August 29, 2011 at 8:33 am

      Hello, it worked for me but the properties for which i changed the order are no more displayed in edit details of my site. The check box to show in edit details is checked in properties configuration. They were shown in edit details previously but after changing the order using script they are not any clue?

    8. Chris
      March 9, 2012 at 5:56 am

      Everytime we run the script we get the following error message:

      New-Object : Exception calling “.ctor” with “1″ argument(s): “Object reference not set to an instance of an object.”
      At line:1 char:30
      + $upConfigManager = New-Object <<< $profilePropertyManager = $upConfigManager.get_ProfilePropertyManager()
      You cannot call a method on a null-valued expression.
      At line:1 char:70
      + $profilePropertyManager = $upConfigManager.get_ProfilePropertyManager <<<< ()
      + CategoryInfo : InvalidOperation: (get_ProfilePropertyManager:String) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull

      We thought this was to do with the URL of our site. We have tried using both the Central admin URL as well as the Mysite URL but both return the same error messages.

      Anyone have any ideas?

      Thanks in advance.

      Chris

    9. Amir Khan
      May 21, 2012 at 4:34 pm

      Someone already built an amazingly simple tool to re-order user profile properties in SP2010.
      Worth downloading.

      http://www.woaychee.com/sharepoint-2010-user-profile-property-reordering/

    10. November 2, 2012 at 3:49 pm

      @Chris : run this code with the farm admin or at least the user that is admin of central admin site.

      @david : Thks for sharing ! usefull script ! :D

    Leave a Reply

    Your email address will not be published. Required fields are marked *