Methods

checkin

(source code)
checkin(setup)
Checkin a file

Parameters:

Object
setup Optional
Options (see below)
String
setup.destination
The full path to the file to check in
String
setup.comments Optional, Default: ""
The comments related to the check in
String
setup.url Optional, Default: 'current website'
The website url
Function
setup.success Optional, Default: function(){}
A callback function that will be triggered when there is success
Function
setup.error Optional, Default: function(){}
A callback function that will be triggered if there is an error
Function
setup.after Optional, Default: function(){}
A callback function that will be triggered after the task

Returns:

Promise
when the request is completed it will trigger the on 'resolve', and no trigger for on 'reject'

Example:

$SP().checkin({
  destination:"http://mysite/Shared Documents/myfile.txt",
  comments:"Automatic check in with SharepointPlus",
  after:function() { alert("Done"); }
});

// with Promise
$SP().checkin({
  destination:"http://mysite/Shared Documents/myfile.txt",
  comments:"Automatic check in with SharepointPlus"
}).then(function() {
  alert("Done");
})

createFile

(source code)
createFile(setup)
Create a file and save it to a Document library

Parameters:

Object
setup
Options (see below)
String
setup.content
The file content
String
setup.filename
The relative path (within the document library) to the file to create
String
setup.library
The name of the document library
Boolean
setup.encoded Optional, Default: false
Set to true if the content passed is already base64-encoded
Object
setup.fields Optional
If you want to set some other fields for the document
String
setup.url Optional, Default: 'current website'
The website url
Function
setup.success Optional, Default: function(fileURL){}
A callback function that will be triggered in case of success; 1 parameter
Function
setup.error Optional, Default: function(fileURL,errorMessage){}
A callback function that will be triggered in case of failure; 2 parameters
Function
setup.after Optional, Default: function(fileURL,errorMessage){}
A callback function that will be triggered after the task whatever it's successful or not; 2 parameters

Returns:

Promise
The 'fileURL' on 'resolve', and 'errorMessage' on 'reject'

Example:

// create a text document
$SP().createFile({
  content:"Hello World!",
  filename:"SubFolder/myfile.txt",
  library:"Shared Document",
  fields:{
    "Title":"My Document",
    "File_x0020_Description":"This is my file!"
  },
  after:function(fileURL, error) {
    if (error) alert("Error: "+error)
    else alert("File created at " + fileURL); // fileURL -> http://mysite/Shared Documents/SubFolder/myfile.txt
  }
});

// you can remove "library" if you use $SP().list()
$SP().list("Shared Document").createFile({
  content:"Hello World!",
  filename:"SubFolder/myfile.txt",
  fields:{
    "Title":"My Document",
    "File_x0020_Description":"This is my file!"
  },
  after:function(fileURL, error) {
    if (error) alert("Error: "+error)
    else alert("File created at " + fileURL); // fileURL -> http://mysite/Shared Documents/SubFolder/myfile.txt
  }
})

// we can also create an Excel file
// a good way to export some data to Excel
$SP().createFile({
  content:"<table><tr><th>Column A</th><th>Column B</th></tr><tr><td>Hello</td><td>World!</td></tr></table>",
  filename:"myfile.xls",
  library:"Excel Exports",
  after:function(fileURL) {
    window.location.href=fileURL;
  }
});

// You can use https://github.com/Aymkdn/FileToDataURI if you want to be able to read a local file
// and then upload it to a document library, via Javascript/Flash
// We'll use "encoded:true" to say our content is already a base64 string
$SP().createFile({
  content:"U2hhcmVwb2ludFBsdXMgUm9ja3Mh",
  encoded:true,
  filename:"Demo/HelloWorld.txt",
  library:"Documents",
  url:"http://my.other.site/website/"
});

// with $SP().list() and Promise
$SP().list("Documents", "http://my.other.site/website/").createFile({
  content:"U2hhcmVwb2ludFBsdXMgUm9ja3Mh",
  encoded:true,
  filename:"Demo/HelloWorld.txt"
}).then(function(file) {
  console.log(file+" has been created")
}, function(error) {
  console.log("Error: "+error)
})

// NOTE: in some cases the files are automatically checked out, so you have to use $SP().checkin()

createFolder

(source code)
createFolder(setup)
Create a folter in a Document library

Parameters:

Object|String
setup
Options (see below), or the folder name when using with $SP().list()
String
setup.path
The relative path to the new folder
String
setup.library
The name of the Document Library
String
setup.url Optional, Default: 'current website'
The website url
Function
setup.after Optional, Default: function(passed,failed){}
A callback function that will be triggered after the task

Returns:

Promise
A 'results' array with 'passed' ([0]) and 'failed' ([1]), no trigger on 'reject'

Example:

// create a folder called "first" at the root of the Shared Documents library
// the result should be "http://mysite/Shared Documents/first/"
$SP().createFolder({
  path:"first",
  library:"Shared Documents",
  url:"http://mysite/",
  after:function() { alert("Folder created!"); }
});

// create a folder called "second" under "first"
// the result should be "http://mysite/Shared Documents/first/second/"
// if "first" doesn't exist then it will be created
$SP().createFolder({
  path:"first/second",
  library:"Shared Documents",
  after:function() { alert("Folder created!"); }
});

// you can also use $SP().list()
$SP().list("Shared Documents", "http://my.web.site").createFolder("first/second").then(function(results) {
  results.forEach(function(folder) {
    if (folder.errorMessage) console.log("The folder << "+folder.BaseName+" >> hasn't been created: "+folder.errorMessage)
    else console.log("The folder << "+folder.BaseName+" >> has been created") })
  })
})

// Note: To delete a folder you can use $SP().list().remove() with ID and FileRef parameters