Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createPage(webUrl,listTitle,fileName,success, failure)
- {
- getListUrl(webUrl,listTitle,
- function(listUrl){
- var fileUrl = listUrl + '/' + fileName
- var url = webUrl + "/_api/web/GetFolderByServerRelativeUrl('" + listUrl + "')/Files" +
- "/AddTemplateFile(urlOfFile='" + fileUrl + "',templateFileType=0)";
- jQuery.ajax({
- url: url,
- method: "POST",
- body: {
- "Title": "Test",
- "JobDescriptionCoreResponsibiliti" : "Testewa",
- "ContentTypeId" : "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D00D1CC7EAA363D486D9DF33F07803859F3"
- },
- headers: {
- "accept": "application/json;odata=verbose",
- "content-type": "application/json;odata=verbose",
- "X-RequestDigest" : jQuery("#__REQUESTDIGEST").val()
- },
- success: function (data) {
- success(data.d);
- },
- error: function (data) {
- failure(data);
- }
- });
- },
- failure
- );
- }
- function getListUrl(webUrl,listTitle,success, failure)
- {
- var url = webUrl + "/_api/web/lists/GetByTitle('" + listTitle + "')/RootFolder";
- jQuery.ajax({
- url: url,
- method: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- "content-type": "application/json;odata=verbose"
- },
- success: function (data) {
- success(data.d.ServerRelativeUrl);
- },
- error: function (data) {
- failure(data);
- }
- });
- }
- //Usage
- createPage(_spPageContextInfo.webAbsoluteUrl,'Pages','Tesxt.aspx',
- function(page){
- console.log(JSON.stringify(page));
- },
- function(error){
- console.log(JSON.stringify(error));
- }
- );
Add Comment
Please, Sign In to add comment