SharePoint 2013 App Development sample (ii) Get user information

Source: Internet
Author: User
Tags bind visual studio

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.