如何使用jsom使用复选框将多个文件从一个文档库复制到sharepoint中的另一个文档库 [英] how to copy multiple files using checkbox from one document library to another in sharepoint using jsom

查看:76
本文介绍了如何使用jsom使用复选框将多个文件从一个文档库复制到sharepoint中的另一个文档库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i have a site collection named 'TestTeam'.in which i have created a document library named 'doclib1'.i have created another document library called 'doclib2'.i want to copy the items (more than one) using checkboxes of doclib1 to doclib2 using jquery or javascript or REST.plz help and provide the complete code.

我已经在下面应用了复制单个项目的代码,一次要复制多个项目:

i have applied code below for copying a single item i want multiple item at a time:

< script type ="text/javascript" src =" https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"</script>
    < script type ="文本/javascript" src ="/script>
    < script>


       函数copyItem(){
            var binary =";        
            $().SPServices({
               操作:"GetItem",
               网址:"https://fte-teams.cbreglobalinvestors.com/sites/dev/TestTeam/docLib1/hello1.xlsx",
                completefunc:函数(xData,状态){                   
                       二进制= $(xData.responseXML).find("Stream").text();                                       
                    $().SPServices({
                       操作:"CopyIntoItems",
                        SourceUrl:"https://fte-teams.cbreglobalinvestors.com/sites/dev/TestTeam/docLib1/hello1.xlsx",
                        DestinationUrls:["https://fte-teams.cbreglobalinvestors.com/sites/dev/TestTeam/copySubsite/docLib2/hello1.xlsx"],
                       流:二进制                     
                        completefunc:函数(xData,状态){
                            console.debug(status);

                        }
                    });
                }
            });}

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
    <script>


        function copyItem() {
            var binary = "";        
            $().SPServices({
                operation: "GetItem",
                Url: "https://fte-teams.cbreglobalinvestors.com/sites/dev/TestTeam/docLib1/hello1.xlsx",
                completefunc: function (xData, Status) {                    
                        binary = $(xData.responseXML).find("Stream").text();                                       
                    $().SPServices({
                        operation: "CopyIntoItems",
                        SourceUrl: "https://fte-teams.cbreglobalinvestors.com/sites/dev/TestTeam/docLib1/hello1.xlsx",
                        DestinationUrls: ["https://fte-teams.cbreglobalinvestors.com/sites/dev/TestTeam/copySubsite/docLib2/hello1.xlsx"],
                        Stream: binary,                        
                        completefunc: function (xData, Status) {
                            console.debug(status);

                        }
                    });
                }
            });}


推荐答案

您可以尝试以下代码:

<script type="text/javascript">
 var context = SP.ClientContext.get_current();
 var web = context.get_web();
 context.load(web); 

 var _destlib = web.get_lists().getByTitle('docLib2');
 context.load(_destlib);

 var _srclib = web.get_lists().getByTitle('docLib1');

 var selectedItems = SP.ListOperation.Selection.getSelectedItems(context); 

 for(var i in selectedItems)
 {
   var currentItem = _srclib.getItemById(selectedItems[i].id);
   context.load(currentItem); 

   var File = currentItem.get_file();
   context.load(File); 

   context.executeQueryAsync
    (
      function (sender, args) {
         if(File != null) { 
            var _destinationlibUrl =  web.get_serverRelativeUrl() + _destlib.get_title() + '/' +  File.get_name(); 

            File.copyTo(_destinationlibUrl, true);
            context.executeQueryAsync(
                function (sender, args) { 
                   alert('File copied successfully');
                },
                function (sender, args) {
                   alert('Error copying file!'+args.get_message());
                });
         }
      },
     function (sender, args) {
        alert('Error occured’ + args.get_message());
     }
   );
 }
</script>

最好的问候,

吴迪(Andy Wu)

Andy Wu


这篇关于如何使用jsom使用复选框将多个文件从一个文档库复制到sharepoint中的另一个文档库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆