In this example, we'll show you how to get user information:
1. Open Visual Studio 2012.
2. Create a new SharePoint 2013 app:userprofiletest.
3. Choose Sharepoint-hosted, finish the spot.
4. Open default.aspx:
Add Knockoutjs and Sp.userprofiles.debug.js (contains user profile information):
<script type= "Text/javascript" src= ". /scripts/knockout-3.0.0.js "></script>
<script type= "Text/javascript" src= "/_layouts/15/sp.runtime.debug.js" ></script>
<script type= "Text/javascript" src= "/_layouts/15/sp.debug.js" ></script>
<script type= "Text/javascript" src= "/_layouts/15/sp.userprofiles.debug.js" ></script>
Modify Title:
<asp:content contentplaceholderid= "Placeholderpagetitleintitlearea" runat= "Server" >
User Information
</asp:Content>
Join User display:
<asp:content contentplaceholderid= "PlaceHolderMain" runat= "Server" >
5. Open App.js Modify as follows:
The first two line references JS provides IntelliSense functionality
<reference path= "Knockout-3.0.0.debug.js"/>///<reference path= "~/_layouts/15/
Sp.userprofiles.debug.js "/> $ (function () {ko.applybindings (New userprofileprops ());});
function Userprofileprops () {var self = this;
Self._currentuser = null;
Self.currentuser = Ko.observable (); Self.load = function () {var context = SP.
Clientcontext.get_current ();
Self._currentuser = Context.get_web (). Get_currentuser ();
Context.load (Self._currentuser); var pm = new SP.
Userprofiles.peoplemanager (context);
Self._props = Pm.getmyproperties ();
Context.load (Self._props); Context.executequeryasync (Function.createdelegate (self, self.onsuccess), Function.createdelegate (
Self, self.onfail));
} self.onsuccess = function () {self.currentuser (self._currentuser); } self.onfail = function (sender, args) {alert ("UnablE To access user information: "+ args.get_message ());
} self.load (); }