Guest User

Untitled

a guest
Feb 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. function createPage(webUrl,listTitle,fileName,success, failure)
  2. {
  3. getListUrl(webUrl,listTitle,
  4. function(listUrl){
  5.  
  6. var fileUrl = listUrl + '/' + fileName
  7. var url = webUrl + "/_api/web/GetFolderByServerRelativeUrl('" + listUrl + "')/Files" +
  8. "/AddTemplateFile(urlOfFile='" + fileUrl + "',templateFileType=0)";
  9. jQuery.ajax({
  10. url: url,
  11. method: "POST",
  12. body: {
  13. "Title": "Test",
  14. "JobDescriptionCoreResponsibiliti" : "Testewa",
  15. "ContentTypeId" : "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D00D1CC7EAA363D486D9DF33F07803859F3"
  16. },
  17. headers: {
  18. "accept": "application/json;odata=verbose",
  19. "content-type": "application/json;odata=verbose",
  20. "X-RequestDigest" : jQuery("#__REQUESTDIGEST").val()
  21. },
  22. success: function (data) {
  23. success(data.d);
  24. },
  25. error: function (data) {
  26. failure(data);
  27. }
  28. });
  29.  
  30. },
  31. failure
  32. );
  33.  
  34.  
  35. }
  36.  
  37.  
  38. function getListUrl(webUrl,listTitle,success, failure)
  39. {
  40. var url = webUrl + "/_api/web/lists/GetByTitle('" + listTitle + "')/RootFolder";
  41. jQuery.ajax({
  42. url: url,
  43. method: "GET",
  44. headers: {
  45. "accept": "application/json;odata=verbose",
  46. "content-type": "application/json;odata=verbose"
  47. },
  48. success: function (data) {
  49. success(data.d.ServerRelativeUrl);
  50. },
  51. error: function (data) {
  52. failure(data);
  53. }
  54. });
  55. }
  56.  
  57.  
  58. //Usage
  59. createPage(_spPageContextInfo.webAbsoluteUrl,'Pages','Tesxt.aspx',
  60. function(page){
  61. console.log(JSON.stringify(page));
  62. },
  63. function(error){
  64. console.log(JSON.stringify(error));
  65. }
  66. );
Add Comment
Please, Sign In to add comment