Sharepoint 2013 – Create an AppPart Sharepoint Hosted

Create a Visual Studio 2012 “App for SharePoint 2013” Project:

app1

Enter your SharePoint url and select the “SharePoint hosted” option:

app2

Add a “Client Web Part Item” to your project:

app3

Select the option “Create a New Client Web Part Page”:

app4

Change the SampleWebPart.aspx to include a label:

app5

Create a SampleWebPart.js file, in the Scripts folder, and  include the script:

‘use strict’;
var context = SP.ClientContext.get_current();

var web = context.get_web();

$(document).ready(function () {

    getWebTitle();

});

function getWebTitle() {

    context.load(web, “Title”);

    context.executeQueryAsync(onGetWebSuccess, onGetWebFail)

}

function onGetWebSuccess() {

  
    $(‘#webTitle’).text(‘Welcome to ‘ + web.get_title());

}

function onGetWebFail(sender, args) {

    $(‘#webTitle’).text(‘Error ‘);

}

Change the SampleWebPart.aspx to include the new script file:

<script type=”text/javascript”src=”../Scripts/SampleWebPart.js”></script>

Edit the AppManifest.xml file to define app permissions:

app8

Deploy your project, and add the webpart to your homepage:

app7

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: