Ads

Friday, 17 February 2017

REST API to Add Template File in Document Library

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 addfile()  
{
    var executor;
 
    // Initialize the RequestExecutor with the app web URL.
    executor = new SP.RequestExecutor(appweburl);
 
    executor.executeAsync({
 
        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 + "'",
        method: "POST",
 
        headers:  
        {
            "accept": "application/json; odata=verbose"
        },
        success: function(data)
        {
            alert("success:WIKI PAGE CREATED SUCCESSFULLY ");
        },
        error: function(err)
        {
            alert("error: " + JSON.stringify(err));
        }
    });
}
   

No comments:

Post a Comment

Ads