Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have followed and successfully implemented the excellent article:

SharePoint 2010 ECMAscript – Copy\Move files to another document library – Part 2

located at:

http://www.learningsharepoint.com/2011/05/28/sharepoint-2010-ecmascript-copymove-files-to-another-document-library-part-2/

Here is the code:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
    Id="CopyingFilesButton"
    Location="CommandUI.Ribbon"
    RegistrationId="101"
    RegistrationType="List"
    Sequence="5"
    Title="Copy Documents">
        <CommandUIExtension>
            <CommandUIDefinitions>
                <CommandUIDefinition
                Location="Ribbon.Documents.Manage.Controls._children">
                    <Button Id="Ribbon.Documents.Manage.CopyDocuments"
                    Command="CopyDocumentsButtonCommand"
                    LabelText="Move To Supplier Invoices"
                    Image32by32="/_layouts/images/MoveToSupplierInvoices/multiplemovebutton.png"
                TemplateAlias="o1" />"
            </CommandUIDefinition>
        </CommandUIDefinitions>
        <CommandUIHandlers>
            <CommandUIHandler
            Command="CopyDocumentsButtonCommand"
            CommandAction="javascript:
                var context = SP.ClientContext.get_current();
                var web = context.get_web();
                context.load(web);
                var _destinationlib = web.get_lists().getByTitle('Shared Documents');
                context.load(_destinationlib);
                var notifyId;
                var currentlibid = SP.ListOperation.Selection.getSelectedList();
                var currentLib = web.get_lists().getById(currentlibid);
                var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
                var count = CountDictionary(selectedItems);
                for(var i in selectedItems)
                {
                    alert('Now moving ' + i);
                    var currentItem = currentLib.getItemById(selectedItems[i].id);
                    context.load(currentItem);
                    var File = currentItem.get_file();
                    context.load(File);
                    //Excecuting executeQueryAsync to get the loaded values
                    context.executeQueryAsync
                        (
                            function (sender, args) {
                                if(File != null) {
                                    var _destinationlibUrl =  web.get_serverRelativeUrl() + _destinationlib.get_title() + '/' +  File.get_name();
                                    alert('Now moving to: ' + _destinationlibUrl);
                                    File.moveTo(_destinationlibUrl, true);
                                    notifyId = SP.UI.Notify.addNotification('Moving file ' + File.get_serverRelativeUrl() + ' to ' + _destinationlibUrl, true);
                                    //Excecuting executeQueryAsync to copy the file
                                    context.executeQueryAsync(
                                        function (sender, args) {
                                            SP.UI.Notify.removeNotification(notifyId);
                                            SP.UI.Notify.addNotification('File moved successfully', false);
                                        },
                                        function (sender, args) {
                                            SP.UI.Notify.addNotification('Error moving file: ' + args.get_message(), false);
                                            SP.UI.Notify.removeNotification(notifyId);
                                            showError(args.get_message());
                                    });
                                }
                            },
                            function (sender, args) {
                                alert('Error occured' + args.get_message());
                            }
                        );
                }"/>
        </CommandUIHandlers>
    </CommandUIExtension>
</CustomAction>

I wanted to change the code to move the documents so I changed the line:

File.copyTo(_destinationlibUrl, true); 

to:

File.moveTo(_destinationlibUrl, true);

(see above) hoping that would work.

Unfortunately, I get the error 'input string was not in a correct format'.

Any ideas on what I'm doing wrong?

Thanks in advance.

Walter

share|improve this question

2 Answers 2

I haven't tested the the File with move, but from the documentation its a flag not a boolean:

SP.File.moveTo(newUrl, flags) 
flags
Specifies the kind of move operation.
It must not have flags other than MoveOperations.Overwrite or MoveOperations.AllowBrokenThickets set.
Type: SP.MoveOperations


SP.File.copyTo(strNewUrl, bOverWrite)
bOverWrite
Specifies whether a file with the same name is overwritten.
Type: Boolean

The different types from the documentation:

none
overwrite
allowBrokenThickets
bypassApprovePermission
share|improve this answer

Try this:

alert('Now moving to: ' + _destinationlibUrl);                                        
File.moveTo(_destinationlibUrl,1); 

It worked for me.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.