sharepoint application page

i need create ribbon button for copying selected documents from one library to another library that i choose. i found javascript code that copy selected documents to library 'shared documents'. the code is

<code>

function RibbonButtonHandler() {

    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(' ' + count + ' м/');
        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();

        File.copyTo(_destinationlibUrl, true);
        notifyId = SP.UI.Notify.addNotification('' + 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(' ', false);
},
function (sender, args) {
    SP.UI.Notify.addNotification(' ', false);
    SP.UI.Notify.removeNotification(notifyId);
    showError(args.get_message());
});
    }
},
function (sender, args) {
    alert(' ' + args.get_message());
}
);
    }

                                                       
                                                          }
                                                          

</code>

how solve this problem? problem is line var _destinationlib = web.get_lists().getByTitle('Shared Documents');. Can i make the changes in javascript that instead shared documents i can choose some library between more libraries?

April 24th, 2015 1:54am

Hi,

You can change the "Shared Documents" to another document library name, if you want to copy the selected documents to more libraries, please change the code like below:

var _destinationlib1 = web.get_lists().getByTitle('Library1');
var _destinationlib2 = web.get_lists().getByTitle('Library2');
var _destinationlib3 = web.get_lists().getByTitle('Library3');
Best Regards

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 2:45am

but i want to copy the selected documents to library that i choose, i don want to copy the documents  to more libraries in same time

thanks

April 27th, 2015 3:18am

i tryed with one more solution. i created an application page. i used code for sending selected items on application page

                                                                                             

 javascript:function demoCallback(dialogResult, returnValue)
              {
                SP.UI.Notify.addNotification(' !');

                SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
              }

              var ctx = SP.ClientContext.get_current();
              var items = SP.ListOperation.Selection.getSelectedItems(ctx);
              var myItems = '';
              var k;

              for (k in items)
              {
                myItems += '|' + items[k].id;
              }

              var options = {              
                url: '/_layouts/RibbonCopyMove/CopyMovePage.aspx?items=' + myItems + '&amp;source=' + SP.ListOperation.Selection.getSelectedList(),
                tite: 'Move Documents',
                allowMaximize: false,
                showClose: false,
                width: 600,
                height: 500,
                dialogReturnValueCallback: demoCallback };

              SP.UI.ModalDialog.showModalDialog(options);

i create copymovepage.aspx with code

    

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CopyMovePage.aspx.cs" Inherits="RibbonCopyMove.Layouts.RibbonCopyMove.CopyMovePage" DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<script language="javascript" type="text/javascript">
function ReadNode() { 
     var treeViewData = window["<%=TreeView1.ClientID%>"+"_Data"]; 
       if(treeViewData.selectedNodeID.value !="") 
            { 
                  var selectedNode = document.getElementById(treeViewData.selectedNodeID.value);
                  var value = selectedNode.href.substring(selectedNode.href.indexOf(",") + 3, selectedNode.href.length - 2);
                  var urlselectedNode = TreeView1.SelectedNode.ValuePath.ToString();
            }
       else
            {  
                  alert(" .")  
            } 
  return false;
   JSRequest.EnsureSetup(); 
  var itemsId = JSRequest.QueryString=["items"];
   }
</script>

</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<table border="0" width="100%">
<tr><td>
<div><h4> /м </h4></div>
<hr  />
<div>
<SharePoint:SPHierarchyDataSourceControl 
  runat="server" id="TreeViewDataSource2" RootContextObject="Web" 
  IncludeDiscussionFolders="False"
  ShowDocLibChildren="true"
  ShowFolderChildren="true"
  ShowListChildren="false"
  ShowWebChildren="true"
/>
<SharePoint:SPTreeView ID="TreeView1" runat="server" DataSourceID="TreeViewDataSource2" EnableViewState="false" ExpandDepth="0"
ShowLines="True" EnableClientScript="true" ShowCheckBoxes="All" AutoExpandSelectedNode="False" TabIndex="3">
 <DataBindings>
  <asp:treenodebinding ImageToolTipField="Name" ImageUrlField="ImageUrl" NavigateUrlField="NavigateUrl" PopulateOnDemand="True" TextField="EncodedName" ToolTipField="Name" ValueField="Name" />

  </DataBindings>
  </SharePoint:SPTreeView>
  </div>
  </td></tr>
  <tr><td align="right">
  <hr />
  <asp:Button ID="button1" Text="" runat="server" TabIndex="1" OnClientClick="ReadNode();" />
  <asp:Button ID="button2" Text="" runat="server" TabIndex="2" OnClientClick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'Cancelled clicked');"  />
  </td></tr></table>

</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">


</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >

</asp:Content>

i don't know how get receive data from query string. i don't know that my code ok  JSRequest.EnsureSetup(); 
  var itemsId = JSRequest.QueryString=["items"];

How that i receive selected node from treeview control? how that i make function that work copying selected data to selected location from treeview control? thanks

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 9:13am

Hi,

We can use Javascript client object model to get selected items, here is a blog for your reference:

Get selected items Javascript client object model SharePoint 2010

http://spdailytips.blogspot.com/2011/08/get-selected-items-javascript-client.html

Best Regards

April 27th, 2015 10:09pm

i used Javascript client object model to get selected items and i pass to application page like query string. how i use this query string on application page for copying documents to another library (another location)?
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 1:22am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics