spsave
Nodejs module for saving files in SharePoint (both on premise and online).
Install:
npm install spsave
Usage:
var spsave = require("spsave");
spsave(options, callback);
Options:
siteUrl
- required, string url of the siteusername
- required, string user namepassword
- required, string passwordfolder
- required, site-relative url to folder, which will be used to save your file. For example for libraryhttp://sp2013/sites/dev/SiteAssets
folder will be equalSiteAssets
,SiteAssets/subfolder
for subfolder. Now you can pass any path, if its not exist, spsave will attempt to create it (thanks @dimkk). For example you can specifySiteAssets/myapp/templates/home
, then full folder hierarchy will be created.fileName
- required, string file namefileContent
- required, string or buffer file content (binary files supported, you can do something like this:fileContent: fs.readFileSync('app/img/logo.png')
)domain
- for on premise only, string domain nameworkstation
- for on premise only, string workstation nameisOnPrem
- optional, function returns boolean, used to determine if the site is SharePoint online or on premise, default implementation -return (urlparse(url)).host.indexOf(".sharepoint.com") === -1;
log
- optional, boolean to enable verbose logging inside spsave, default is falseappWebUrl
- optional, site-relative string url to your app web (for apps development). For example if your root web ishttp://sp2013.com/sites/dev
and app full url ishttp://sp2013-apps.[guid].com/sites/dev/yourapp
, thenappWebUrl
will beyourapp
checkin
- optional, boolean to allow the files to be checked in/published.checkinType
- optional when using checkin. value 1 or 'major' allow a major version of the file is published. Value 0 or 'minor' allow a minor version of the file to be checked in. Value 2 or 'overwrite' allows contents of the current file version to be overwritten.
Callback
Function which accepts error object as first argument and result of file upload as second.
Samples
Upload file file.txt
to SharePoint online site into the SiteAssets library:
var spsave = require("spsave");
spsave({
siteUrl: "https://[domain].sharepoint.com/sites/dev",
username: "[user]@[domain].onmicrosoft.com",
password: "[password]",
folder: "SiteAssets",
fileName: "file.txt",
fileContent: "hello world"
}, function(err, data){
if(err){
console.log("Error occurred");
} else{
console.log(data);
}
});
SharePoint on premise version:
var spsave = require("spsave");
spsave({
siteUrl: "[siteurl]",
username: "[username]",
password: "[password]",
workstation: "[workstation name]",
domain: "[domain name]",
folder: "SiteAssets",
fileName: "file.txt",
fileContent: "hello world"
}, function(err, data){
if(err){
console.log("Error occurred");
} else{
console.log(data);
}
});
Develop
npm install -g mocha supervisor
Test:
mocha
- will run tests in test
folder
npm run autotest
- will run autotesting