Develop the project using the following method in the NAPA Tool.

On your Developer Site, open the "Napa" Office 365 Development Tools and then choose Add New Project.



Prerequisites

The following are important steps to be done before creating the app. Specify the permissions that your app needs as in the following. Choose the Properties button at the bottom of the page.


Default ASPX: CodeUnderstanding



Note:

The SP.TemplateFileType creates the file: Standard Page = 0; WikiPage = 1; FormPage = 2.

Source Code
  1. 'use strict';
  2. var hostweburl;
  3. var appweburl;
  4. // Get the URLs for the app web the host web URL from the query string.
  5. $(document).ready(function()
  6. {
  7. //Get the URI decoded URLs.
  8. hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
  9. appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
  10. // Resources are in URLs in the form:
  11. // web_url/_layouts/15/resource
  12. // Load the js file and continue to load the page with information about the folders.
  13. // SP.RequestExecutor.js to make cross-domain requests
  14. $.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js", addfile);
  15. });
  16. //Retrieve all of the folders from root Site
  17. function addfile()
  18. {
  19. var executor;
  20. // Initialize the RequestExecutor with the app web URL.
  21. executor = new SP.RequestExecutor(appweburl);
  22. executor.executeAsync({
  23. url: appweburl + "/_api/SP.AppContextSite(@target)/web/getfolderbyserverrelativeurl('/sites/apps/Shared Documents')/files/addtemplatefile(urloffile='/sites/apps/Shared Documents/wikipage.aspx',templatefiletype=1)?@target='" + hostweburl + "'",
  24. method: "POST",
  25. headers:
  26. {
  27. "accept": "application/json; odata=verbose"
  28. },
  29. success: function(data)
  30. {
  31. alert("success:WIKI PAGE CREATED SUCCESSFULLY ");
  32. },
  33. error: function(err)
  34. {
  35. alert("error: " + JSON.stringify(err));
  36. }
  37. });
  38. }
  39. //Utilities
  40. // Retrieve a query string value.
  41. // For production purposes you may want to use a library to handle the query string.
  42. function getQueryStringParameter(paramToRetrieve) {
  43. var params = document.URL.split("?")[1].split("&");
  44. for (var i = 0; i < params.length; i = i + 1) {
  45. var singleParam = params[i].split("=");
  46. if (singleParam[0] == paramToRetrieve) return singleParam[1];
  47. }
  48. }
Publish

Publish the app and click the Trust it Button.



Output

Template FILE Created Successfully in Document Library.