Programmatically create User Profile Sub-Types in SharePoint 2010

Posted by in SharePoint category on for Intermediate level | Points: 250 | Views : 9593 red flag

In this article you will see how to create User Profile Sub-Types in SharePoint 2010.

User Profile Sub-Types:

User properties can be associated to the particular user Profile Sub Type and these sub types allows creating different kinds of User Profiles. Each User Profiles will display different user properties based on the Sub Types. In this you will see how to create User Profile sub types in SharePoint 2010 using SharePoint Object Model.

Steps Involved:

1. Open Visual Studio 2010 by going Start | All Programs | Microsoft Visual Studio 2010 | Right click on Microsoft Visual Studio 2010 and click on Run as administrator.

2. Go to File tab, click on New and then click on Project.

3. In the New Project dialog box, expand the Visual C# node, and then select the Windows node.

4. In the Templates pane, select Console Application.

5. Enter the Name and then click OK.

6. In the solution explorer, right click on the solution and then click on Properties.

7. Select the Application tab, check whether “.Net Framework 3.5” is selected for Target Framework.

8. Select the Build tab, check whether “Any CPU” is selected for Platform Target.

9. In the solution explorer, right click on the References folder and click on Add Reference.

10. Add the following references.

  1.  Microsoft.SharePoint.dll
  2.  Microsoft.Office.Server.UserProfiles.dll
  3.  System.Web.dll

11. Double click on Program.cs and add the following Namespaces.

  1.  using System.Web;
  2.  using Microsoft.Office.Server.UserProfiles;
  3.  using Microsoft.SharePoint; 

12. Replace Program.cs with the following code snippet.


namespace UserProfileTesting


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Web;

using Microsoft.Office.Server.UserProfiles;

using Microsoft.SharePoint;


class Program


public static void Main(string[] args)


using (SPSite site = new SPSite(""))


//// SPServiceContext class is used to represent a context object that encapsulates all the information that is required to make a call to a user profile service application.

SPServiceContext context = SPServiceContext.GetContext(site);

////ProfileSubtypeManager class is used to create, delete, retrieve, and manage profile subtypes for a profile type.

ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);

//// Get the user profile subtype

ProfileSubtype subtype=psm.GetProfileSubtype("Finance");

//// Check whether the subtype exists

if (subtype == null)


//// create a new user profile subtype

//// Finance is the Name of the subtype

//// Finance Subtype is the Display name of the subtype

psm.CreateSubtype("Finance", "Finance Subtype", ProfileType.User);




Console.WriteLine(subtype.DisplayName + " already exists.");








13. In the solution explorer, right click on the solution and click on Build.

14. Hit F5.


Thus in this article you have seen how to create User Profile Sub-types using SharePoint object model.

Thanks for reading.

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Vijai Anand R
Member Level: Starter
Member Status: Member
Member Since: 5/22/2011 5:12:38 AM
Country: India
Vijai Anand.R
SharePoint Developer

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)