Examples:
You will learn the concepts using the code snippets that we come across in SharePoint Apps development.
Below is the code snippet you will get it under App.js file when you create SharePoint-Hosted app using visual studio 2012.
1234567891011121314151617181920212223242526272829 |
var context;
var web;
var user;
// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
$(document).ready(function () {
context = SP.ClientContext.get_current();
web = context.get_web();
getUserName();
});
// This function prepares, loads, and then executes a SharePoint query to get the current users information
function getUserName() {
user = web.get_currentUser();
context.load(user);
context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
}
// This function is executed if the above OM call is successful
// It replaces the contents of the 'helloString' element with the user name
function onGetUserNameSuccess() {
$('#message').text('Hello ' + user.get_title());
}
// This function is executed if the above call fails
function onGetUserNameFail(sender, args) {
alert('Failed to get user name. Error:' + args.get_message());
}
|
Here is a good article for SharePoint App Development:
http://www.sharepoint-journey.com/app-development-in-sharepoint.html
No comments:
Post a Comment