Showing posts with label User Profile. Show all posts
Showing posts with label User Profile. Show all posts

Thursday, February 23, 2017

SharePoint 2010/2013 Display user information using ProfilePropertyLoader

Hi Folks,

This article talks about the best way to get the user profile properties on page.

Sometimes we come across the requirement asking to show the User related information on the page.
Generally we write code by accessing User Information list to get the User related data.

In such cases, rather than writing code SharePoint gives us the provision to read the User data.

SharePoint has something called "ProfilePropertyLoader" control which will be available in any SharePoint page which has the below register tag.

<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Follwing are the tags we need to add to the page inoder to read the current user Name and Email.

User Name
The first line below is needed to load and make the profile properties available.

<SPSWC:ProfilePropertyLoader runat="server"/>

<SPSWC:ProfilePropertyValue PropertyName="FirstName" ApplyFormatting="False" runat="server" ShowPrivate="True" PrefixBrIfNotEmpty="False"/>

<SPSWC:ProfilePropertyValue PropertyName="LastName" ApplyFormatting="False" runat="server" ShowPrivate="True" PrefixBrIfNotEmpty="False"/>

Email
<SPSWC:ProfilePropertyValue cssClass="loggedin" PropertyName="WorkEmail" ApplyFormatting="False" runat="server" ShowPrivate="True" PrefixBrIfNotEmpty="False"/>


Hope this helps...

RELATED POST: How to get current user info using jquery spservices



Wednesday, May 15, 2013

jQuery SPServices to get current user sharepoint groups

In this post we are going to get information of all the sharepoint user groups in which current user belongs using SPServices.

Below is the jQuery code snippet which will do this action.
In this example we will be looping all the groups which the current user is present and adding it to the variable  loggedinUserGroup.

// add the ref of jQuery file
<script type="text/javascript" src="/style library/jquery-1.7.2.js"></script>
// add the ref of jQuery SPServices file
<script type="text/javascript" src="/style library/jquery.SPServices-0.7.0.min.js"></script>
<script type="text/javascript">
var loggedinUserGroup;
$(document).ready(function() {
 Getrolesforuser();
 alert(loggedinUserGroup);
});
function Getrolesforuser()
{
 loggedinUserGroup="";
 $().SPServices({ 
  operation: "GetGroupCollectionFromUser", 
        userLoginName: $().SPServices.SPGetCurrentUser(), 
        async: false, 
        completefunc: function(xData, Status)
        {
         $(xData.responseXML).find("Group").each(function()
         {
              if(loggedinUserGroup=="")
              {
                  loggedinUserGroup = $(this).attr("Name");
              }
              else
              {
                  loggedinUserGroup = loggedinUserGroup + "\n"+ $(this).attr("Name");
              }
         });
               
  }
 });
}

</script>

Hope this helps... Follow this page for more updates.
Related post- jQuery spservices to get current user name for sharepoint site
Related post- How to display user information using ProfilePropertyLoader in sharepoint

Popular Posts