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());

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


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