var ECMACopyFile;
var ECMACopycontext
var ECMACopyweb;
var ECMACopy_destinationlib;
var notifyId;
function CopyDocumentListFile() {
ECMACopycontext = SP.ClientContext.get_current();
ECMACopyweb = ECMACopycontext.get_web();
ECMACopycontext.load(ECMACopyweb);
ECMACopy_destinationlib = ECMACopyweb.get_lists().getByTitle('My Shared Documents'); //Get Destination Document List
//ECMACopy_destinationlib = ECMACopyweb.get_lists().getByTitle('MyBackupDocuments'); //Get Destination Document List
ECMACopycontext.load(ECMACopy_destinationlib);
var currentlibid = SP.ListOperation.Selection.getSelectedList();
var currentLib = ECMACopyweb.get_lists().getById(currentlibid);
var selectedItems = SP.ListOperation.Selection.getSelectedItems(ECMACopycontext);
var count = CountDictionary(selectedItems);
for (var i in selectedItems) //Loop the Source Document Files
{
alert('Now copying Document :' + i);
var currentItem = currentLib.getItemById(selectedItems.id);
ECMACopycontext.load(currentItem);
//debugger;
ECMACopyFile = currentItem.get_file(); //Get the source file
ECMACopycontext.load(ECMACopyFile);
ECMACopycontext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededCopyDocumentListFile),
Function.createDelegate(this, this.onQueryFailedCopyDocumentListFile));
}
}
function onQuerySucceededCopyDocumentListFile(sender, args) {
if (ECMACopyFile != null) {
debugger;
var ECMACopy_destinationlibUrl = ECMACopyweb.get_serverRelativeUrl()
+ ECMACopy_destinationlib.get_title() + '/'
+ ECMACopyFile.get_name();
notifyId = SP.UI.Notify.addNotification('Copying file…' + ECMACopyFile.get_serverRelativeUrl()
+ 'to' + ECMACopy_destinationlibUrl, true);
ECMACopyFile.copyTo(ECMACopy_destinationlibUrl, true); //Copy the selected File to Destination Document List
// ECMACopyFile.moveTo(ECMACopy_destinationlibUrl,1); //Move the selected File to Destination Document List(Overwrite the file with the same name if it exists)
//ECMACopyFile.moveTo(ECMACopy_destinationlibUrl, SP.MoveOperations.AllowBrokenThickets);
// ECMACopyFile.moveTo(ECMACopy_destinationlibUrl, SP.MoveOperations.Overwrite);