none
Move a single file from one subfolder to another using javascript

    질문

  • hello,

    I would like to ask a question regarding moving a single file with javascript using the elements.xml file in visual studio 2010.

    I modified the code found at :
    http://sharepoint.stackexchange.com/questions/33043/moveto-and-moving-documents-from-one-library-to-another in order to successfully move the file to the root of a library, in my case the library is called "policies"

    The problem I am running into, is that I cannot specify a subfolder location inside of my library as the "var _destinationlib" variable location, I would like to have the destination set as \library\subfolder.

    Could someone please help me with the correct syntax

    Thank you

    <?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 Selected File"
                Image32by32="http://moss/sites/Forms/CoreTeam/PublishingImages/microsoft-office-1.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('Policies'); 
                    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, SP.MoveOperations.overwrite); 
                                        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>
    </Elements>

    2012년 6월 13일 수요일 오후 4:30

모든 응답