I want a script in javascript that can upload a document to the document library.
I know that HTML5 Browsers can do this with ease because I can simply use the FileReader API but how do I do this for older non HTML5 browsers?
I want a script in javascript that can upload a document to the document library.
I know that HTML5 Browsers can do this with ease because I can simply use the FileReader API but how do I do this for older non HTML5 browsers?
You can use jQuery widget for do this.
http://paultavares.wordpress.com/2012/04/28/sharepoint-ui-widgets-upload-and-pickusers/
This plugin uses SPServices
$("#uploadDivContainer").SPControlUpload({
listName: "Shared Documents",
onPageChange: function(ev){
// If we're done with the upload, then continue to show the
// overlay, and fade out the area that contained the upload control.
if (ev.state == 3 && ev.isUploadDone) {
ev.hideOverlay = false;
$('<div style="padding: 1em; width: 80%; margin: 3em auto;" class="ui-state-highlight">Upload Successful!!!</div>')
.appendTo(uiUploadWidget.empty())
.fadeOut(4000, function(){
$(this).remove();
});
// Reload files into viewing area.
refreshFileList();
// If file was uploaded, but we have required fields to fill out,
// then adjust page to only show that...
} else if (ev.state == 3) {
ev.page.find("form")
.children(":visible")
.css("display", "none")
.addClass("ptWasVisible")
.end()
.find("input[title='Name']")
.closest("div[id^='WebPart']")
.appendTo(ev.page.find("form"));
}
}//end: onPageChange()
});
Due to security concerns, you cannot access the file system from JavaScript; you can only perform web related activities (at least when ran from a web browser).
From the JavaScript Wikipedia article:
JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using two restrictions. First, scripts run in a sandbox in which they can only perform web-related actions, not general-purpose programming tasks like creating files.
Your only options in Office 365 are to use a provider hosted app and CSOM, or to use a flash-based tool such as Uploadify.