The requirement is as follows:
1. We have a SP list. All items in the list have mulitple attachments.
2. On click of a button, All the attachments of all items should be copied to a document library
This is to be done from client side only. No server code is acceptable. We have tried following things:
1. USing Asynch call
context = new SP.ClientContext(“my site name”);
this.oWebsite = context.get_web();
var lists = oWebsite.get_lists();
var list = lists.getByTitle(‘my list name’);
context.load(oWebsite);
var folderPath = ‘Lists/<my list name>/Attachments/’ + folderId;
var Folder = oWebsite.getFolderByServerRelativeUrl(folderPath);
context.load(Folder);
Files = Folder.get_files();
context.load(Files);
context.executeQueryAsync(Function.createDelegate(this, this.ExecuteCopyOnSuccess), Function.createDelegate(this, this.ExecuteCopyOnFailure));
function ExecuteCopyOnSuccess(sender, args) {
for(var p=0;p<this.Files.get_count();p++)
{
var file = Files.itemAt(p);
var filename = file.get_name();
if (filename != null) {
var newUrl = ‘document library url’;
file.copyTo(newUrl, true);
context.executeQueryAsync(null,null);
}
}
}
In this case, Files.get_count() throws error – The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
2. Using copy.asmx service
It copies files to document library but some files are blank and are having size 0.
Any pointers for above issue ..
Thanks in Advance …!
Hi Mihir! I am also searching for the exact same functionality…to copy attachments from one list item to another….! Have you found a solution yet..Because so far I could not find an answer. Please let me know if you have found one 🙂 Thank You!