Hope you have idea how to create SharePoint App.
If you are using NAPA tool then replace below codes in APP.js file.
So i am just focusing on the REST script part to do the activities
I recommend to go through REST API for SP document libraries before proceed.
HTML file in Default.aspx
----------------------
JS script in app.js (Paste the below methods in app.js file) Refer here
-----------------------
function createSPList() {
$.ajax(
{
url: appweburl +
"/_api/SP.AppContextSite(@target)/web/lists?@target='" +
hostweburl + "/sites/apps'",
type: "POST",
data: JSON.stringify({
'__metadata': { 'type': 'SP.List' },
'AllowContentTypes': true,
'BaseTemplate': 100,
'ContentTypesEnabled': true,
'Description': 'My TestCustomList description',
'Title': 'TestCustomList'
}),
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: successHandler,
error: errorHandler
});
}
function successHandler() {
$('#message').text('Success');
}
function errorHandler(data, errorCode, errorMessage) {
$('#message').text('Error ' + errorMessage);
}
If you are using NAPA tool then replace below codes in APP.js file.
So i am just focusing on the REST script part to do the activities
I recommend to go through REST API for SP document libraries before proceed.
HTML file in Default.aspx
----------------------
JS script in app.js (Paste the below methods in app.js file) Refer here
-----------------------
function createSPList() {
$.ajax(
{
url: appweburl +
"/_api/SP.AppContextSite(@target)/web/lists?@target='" +
hostweburl + "/sites/apps'",
type: "POST",
data: JSON.stringify({
'__metadata': { 'type': 'SP.List' },
'AllowContentTypes': true,
'BaseTemplate': 100,
'ContentTypesEnabled': true,
'Description': 'My TestCustomList description',
'Title': 'TestCustomList'
}),
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: successHandler,
error: errorHandler
});
}
function successHandler() {
$('#message').text('Success');
}
function errorHandler(data, errorCode, errorMessage) {
$('#message').text('Error ' + errorMessage);
}
No comments:
Post a Comment