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.
- Choose the App for SharePoint template, name the project Create Site and then choose the Create button.
- Replace APP.js with the following source code below.
- Publish Your App.
Prerequisites
These 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.
- In the Properties window, choose Permissions.
- In the Content category, set Write permissions for the Tenant scope.
- In the Social category, set Read permissions for the User Profiles scope.
- Close the Properties window.
Default ASPX
Code Understanding
Note
Endpoint URI
- http://<site url>/_api/web/getfilebyserverrelativeurl('/<folder name>/<file name>')/versions
HTTP methods
This resource supports the following HTTP methods:
GET | POST
Source Code
- 'use strict';
-
- var hostweburl;
- var appweburl;
-
-
-
- $(document).ready(function()
- {
-
-
- hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
- appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
-
-
-
-
-
-
-
- $.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js", versionfile);
- });
-
-
-
- function versionfile()
- {
- var executor;
-
-
- executor = new SP.RequestExecutor(appweburl);
-
- executor.executeAsync
- ({
-
- url: appweburl + "/_api/SP.AppContextSite(@target)/web/GetFileByServerRelativeUrl('/sites/apps/Shared Documents/RESTFolder.docx')/versions?@target='" + hostweburl + "'",
- method: "GET",
-
-
- headers:
{
- "accept": "application/json; odata=verbose"
- },
- success: SuccessHandlerFileVersions,
- error: ErrorHandlerFileVersions
- });
- }
-
- / Success Handler
- Function SuccessHandlerFileVersions (data)
- {
- var FV;
- var jsonObject = JSON.parse(data.body);
- var results = jsonObject.d.results;
- for (var i = 0; i < results.length; i++)
- {
- FV += results[i].VersionLabel + '\n';
- }
- / / Display the File versions
- alert(FV);
- }
-
- function ErrorHandlerFileVersions(data, errorCode, errorMessage)
- {
- alert("Could not get the file versions: " + errorMessage);
- }
-
-
-
-
- function getQueryStringParameter(paramToRetrieve)
- {
- var params = document.URL.split("?")[1].split("&");
- for (var i = 0; i < params.length; i = i + 1)
- {
- var singleParam = params[i].split("=");
- if (singleParam[0] == paramToRetrieve) return singleParam[1];
- }
- }
Publish
Publish the App and click the Trust it Button.
Output
File Version retrieved successfully.