SharePoint 2013 Principal Type from a User, Active Directory or SharePoint Group

this article is also ready for SharePoint 2010 on-premise, not available on Office 365 at the moment on this way.

We would like to have a function to check what the principal type of a people picker, we made a demo code to do this.  see:

//The code block write the information about your principal type. ( SharePoint Group, SharePoint User of Active directory user )
            //This code block is only allowed in full trust SharePoint solutions. This is not ready for SharePoint Online.
            //The reason is that the SPUtility.ResolvePrincipal only for full trust solutions.
            using (SPSite site = new SPSite(SPContext.Current.Site.ID))
            {
                using (SPWeb web = site.OpenWeb(site.RootWeb.ID))
                {
                    var principalInfo = SPUtility.ResolvePrincipal(web, web.CurrentUser.LoginName, SPPrincipalType.All, SPPrincipalSource.All, null, false);
                    Label label = new Label();
                    label.Text += string.Format(“Security Type: {0}”, principalInfo.PrincipalType.ToString());
                    this.Controls.Add(label);
                }
            }

the result of this code block in a simpel webpart is:

Capture

the yellow selection is the loginname this can be also the name of the sharepoint group or active directory group

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.