Click here to Skip to main content
12,067,614 members (55,865 online)
Click here to Skip to main content
Add your own
alternative version



SharePoint - Copy Files / Documents from Search screen using JavaScript

, 25 Feb 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
CodeProjectOne of the major enhancement of SharePoint 2010 is "Content Organizing" which makes it more strong in "Document Management System (DMS)" race.Content Organizing means, the content automatically routed to different destinations based up on various factors.Best part of it, content is organi
One of the major enhancement of SharePoint 2010 is "Content Organizing" which makes it more strong in "Document Management System (DMS)" race.

Content Organizing means, the content automatically routed to different destinations based up on various factors.

Best part of it, content is organized without any manual intervention.

Worst part of it, Data / Docs are scattered across site collection or whole web application.

Lets consider a scenario, where the user uploaded 20 documents which were organized into multiple libraries in a site collection. Now i want to bring all that 20 docs to one single library where the user can edit them and resubmit.

Let me show you what i am aiming for.

First Question "Why Search?"
As we discussed content organizer will route the documents in all directions which will change in future, so we cannot rely on "SPSiteDataQuery". SO search will fetch the docs where ever they are across farm.

Now second Question "Why OOTB stuff, we can design a beautiful Custom page with Search API?"
Yeah its not that you cannot, but you cannot imagine how painful it will be while migrating to next version of SharePoint with all the customization.

We are doing all of it using JavaScript, as it will be easy to migrate to SharePoint 2013 apps with no server code.

# Create a site collection which is search enabled and the content of it is searchable.

# Create a webpart page and add below webparts in respective order, so that they appear in reverse order on screen.
         1. Search Core Results webpart.
         2. Search Box webpart.
         3. Content Editor webpart.

# Edit "Search Box" webpart and go to "Miscellaneous" section of its properties and ensure that Target search results page pointing to self. Else the search action will take user to default search results page.

 # Edit "Search Core Results" webpart, go to Display Properties section of its properties and  un-check "Use Location Visualization", now XSL Editor button will be enabled.

# Click "XSL Editor" button and start editing XSLT of the webpart. Search for "srch-Icon", and add below piece of markup.

<input type="checkbox" id="{concat($currentId,'_Checkbox')}" align="absmiddle" class="documentcheckbox"></input><label style="display:none"><xsl:value-of  select="$url"/></label>

This will add a visible check-box and an invisible url of the document. 

# Consider a standard place to keep your Script files. I choose "Style Library", and create a folder "JSApps" and then add below mentioned files.
             1. Jquery.min.js
             2. Script file in txt format, used to load in Content Editor webpart.
Don't worry about the content of the SPScript.txt file now.

# Edit "Content Editor" webpart and go to Content Link section in properties and give url for the SPScript.txt file. Apply the changes and whatever you put in that SPScript.txt file will start effecting the search page.

# Now add below content tp SPScript file and the page will turn just like how it appears on the very first snapshot provided.
<script src="/sites/TestSC/Style Library/JSApps/jquery-1.10.1.min.js"></script>
To make it sweet and short, all i did is,
    1. When a User selects a file, i keep track of the relative url of the selected file.
    2. When a user un-check a file, it will remove the pertaining url from the track.
    3. Once the user selects all the files to be copied, and when he clicks the "Copy To Destination Library", using JavaScript (ECMA), the selected files will be copied to destination library.
   4. User will be notified while copying the files and after successful copying.
   5. If the content type of Source and destination libraries match, it will even copy the metadata.

The only piece of code here is that SPScript File which you can download from this link. Search for "" file.

Note: This piece of code works only to copy files with-in the Site collection. If you intend to copy across different site collections, well that's my next article.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Comments and Discussions

QuestionCross Site Collection part? Pin
Member 1116118520-Oct-14 14:59
memberMember 1116118520-Oct-14 14:59 
GeneralGood job mate Pin
Steven Oberholzer11-May-14 20:37
memberSteven Oberholzer11-May-14 20:37 
QuestionCopy to other Website Pin
FlipperDo@live.de11-Apr-14 0:10
memberFlipperDo@live.de11-Apr-14 0:10 
AnswerRe: Copy to other Website Pin
PratapReddyP14-Apr-14 13:35
memberPratapReddyP14-Apr-14 13:35 
QuestionUniversal processing ID? Pin
Member 1011709826-Feb-14 7:34
memberMember 1011709826-Feb-14 7:34 
AnswerRe: Universal processing ID? Pin
PratapReddyP26-Feb-14 10:21
memberPratapReddyP26-Feb-14 10:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160208.1 | Last Updated 25 Feb 2014
Article Copyright 2014 by PratapReddyP
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid