Vadim Tabakman

How would you go about automating copying all folders and their files from one Document Library to another using Nintex Workflow?

SharePoint exposes 2 web services that help us here. The Lists and Copy web services.

The Lists web service lets us query the source document library using the GetListItems web method and find out what files we have that need to be copied.

The Copy web service allows us to copy files from one location to another using the CopyIntoItemsLocal web method.

The Workflow

First, we use the Nintex Workflow Query List action to query the source document library, to get all the folders. In this article, my document library only has folders in the root of the document library so we can be sure that by running a Query List action, we will only get a list of folders.



We store this in a Collection variable and then iterate through the collection using a For Each action.



In the For Each action, we call the Lists web service to get the list of files in the current folder. The result is in XML, so we use the Query XML action to parse the XML using XPath to get the filenames.





We should now have a collection variable that contains the filenames of all the files in the folder we are currently looking at. Now we need to iterate through the collection of filenames and copy them to our destination folder.



In order to use the CopyIntoItemsLocal web method, we need to build up the source and destination URLs. To do this, we create 2 Nintex Workflow text variables and use the Build Dynamic String action to create the 2 URLs.

Source


Destination


The final 2 actions of the workflow are the core of this workflow. We need to create the destination folder and then copy the source item into that folder.

We can use the Create an Item action to create the folder, because if this folder does not exist, it will create it, and if it does exist, then it will not throw an error and break the workflow.



Now that we are sure the folder exists, we can use the CopyIntoItemsLocal web method in the Copy web service to copy the item.



In Conclusion

This workflow will run on an item in the destination Document Library, and copy the folders and their contents from a source library. I hardcoded the source library name, but there really isn't any reason why it couldn't be used dynamically.

As I've mentioned in previous articles, this is not necessarily a solution that you can import into your environment and just use. It is however, a good starting point if you have a need to do something of this nature.

Downloads

Posted by Vadim Tabakman Sunday, February 5, 2012 10:12:00 PM Categories: Collection Variable Copy.asmx For Each Lists.asmx Nintex Nintex Workflow Query List Query XML
Copyright Vadim Tabakman
Rate this Content 4 Votes

Comments

Wednesday, April 4, 2012 9:22:49 AM
Yvette McGlawn

re: Nintex Workflow - Copying a Document Library Folder and Contents

Vadim:

This will be very helpful, but I need a little more help.  I have files emailed into one library, but need them moved into another library depending on the location field.  Is this possible with a automatic workflow?

 

yvette.mcglawn@anscollc.com

336-852-3433

Wednesday, April 4, 2012 8:10:37 PM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Yvette,

create your workflow on the library that gets emailed.  Then have this workflow perform the copy.

Configure this workflow to start when an item is created.

Tuesday, October 16, 2012 4:39:05 AM
Tobias

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Vadim,

works like a charm!

Wednesday, November 7, 2012 12:01:04 AM
Fati

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi

I need to copy files into local destination ( I don't have folder beacuse all files save in this document library) so How can move file to local destination?

Thanks for your useful blog

 

Thursday, November 8, 2012 10:11:11 PM
Fati

re: Nintex Workflow - Copying a Document Library Folder and Contents

I have find the action about copy file into local folder ("I forget it :) ")

Thanks

Thursday, November 8, 2012 11:12:07 PM
Vadim Tabakman
Gravatar

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Fati, I'm glad you found a solution. :) Vadim
Wednesday, April 10, 2013 9:28:51 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Can you explain the download file or do you have any information on how exactly this works?

Thanks,

John S Parker

Wednesday, April 10, 2013 9:30:36 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi John,

what do you mean the download file?  The file you can download from this post is a Nintex Workflow 2007 exported workflow.

You should then be able to import that into a Nintex Workflow 2007 (or 2010) environment.

cheers,

Vadim

Friday, September 27, 2013 7:16:09 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Vadim,

Is there any way to copy wsp form solutions gallery (Site Settings> galleries> Solutions) to another solution gallery using nintex workflow? 

Thanks in advance :)

Friday, November 1, 2013 5:27:05 AM
Sérgio

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hello Vadim.

Is this WF a Site Workflow? Or it belongs to the source or destination library?

Thank You for your useful tips.

Regards.

Friday, November 1, 2013 7:43:18 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Sergio,

this is a List workflow.  If you're using NW2010 or NW2013, you can wrap all this up into an Action Set, save it as a snippet and then create a Site Workflow and drag it on.  It should work fine.

cheers,

Vadim

Wednesday, December 4, 2013 9:57:31 AM
Fernando Hunth

re: Nintex Workflow - Copying a Document Library Folder and Contents

It seems not to work with subfolders

Wednesday, December 4, 2013 9:59:53 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Fernando,

do you mean it doesn't work if the there are subfolder in the folder you're trying to copy?

cheers,

Vadim

Monday, January 13, 2014 3:04:30 PM
Joseph Libson

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hello Vadim!  Long time reader...first time poster.  :)

First off, thanks for all of your answers to questions on the boards.

For this case I am running into what I assume is some "rookie" problem.  I am trying to set

<QueryOptions><Folder>blah</Folder><QueryOptions>

But it seems to only ever return the contents at the top of the Document Library.

A short video shown here: http://screencast.com/t/KVfzkSuoi

Any help would be greatly appreciated.

Best Regards,

Joe

Tuesday, January 14, 2014 9:55:04 PM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hey Joseph,

I haven't had much luck with the QueryOptions.  Try something like this:

<Query>
  <Lists>
    <List ID="{76C633B6-5A25-4071-9485-40405ADC54AD}" />
  </Lists>
  <ViewFields>
    <FieldRef Name="FileRef" />
  </ViewFields>
  <Where>
    <Contains>
      <FieldRef Name="FileRef"  />
      <Value Type="Lookup">/blah/</Value>
    </Contains>
  </Where>
  <ViewAttributes Scope="Recursive" />
</Query>

cheers,

Vadim

Thursday, March 13, 2014 8:37:15 AM
Pankaj

re: Nintex Workflow - Copying a Document Library Folder and Contents

What if the username and password change every 90 days, do you have to go back and update?

Thursday, March 13, 2014 9:27:51 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Pankaj,

yes you do.  Otherwise, create an account that is not used by users, and instead is more of a system account so that it's password is not changed.

cheers,

Vadim

Thursday, May 1, 2014 6:49:28 AM
Stan Laper
Gravatar

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hey, Do you have a better solution for NW2010?

Thursday, May 1, 2014 7:25:55 AM
Stan Laper
Gravatar

re: Nintex Workflow - Copying a Document Library Folder and Contents

You solution fails to fill values for Lookup columns from source library to target library.

Saturday, May 3, 2014 11:56:34 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Stan, thanks I'll take a look that as soon as I can. cheers, vad
Saturday, October 25, 2014 7:08:13 AM
Ram
Gravatar

re: Nintex Workflow - Copying a Document Library Folder and Contents

It is creating all the documents with created by value as web service account  . Please let me know whether below fields will be copied to destination folder

Created by

Modified by

Saturday, October 25, 2014 10:29:38 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Ram,

no it won't. SP won't let you update the Created By and Modified By fields. They are controlled by SharePoint and will be set as the account used to create/modify the item at the destination.

cheers,

Vadim

Monday, November 10, 2014 12:17:01 PM
Albert Reilingh
Gravatar

re: Nintex Workflow - Copying a Document Library Folder and Contents

I have a slightly different problem.

I have a form created off a list.  The list has folders.  The folders are committees.  When someone creates a new form, I want to create a folder in the document library with the committee name (folder) that they have completed the form in the list.  I am having problems capturing the source folder name.  Any ideas?

Thanks.

Albert

Monday, November 10, 2014 1:37:39 PM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Albert,

Do you meant the source folder from a URL?

You'll probably need to parse the url and pull things out of it until you're left with the folder name.

Using fn-SubString and Regular Expressions and fn-Replace function.

cheers,

Vadim

Wednesday, November 12, 2014 1:11:39 PM
Albert Reilingh
Gravatar

re: Nintex Workflow - Copying a Document Library Folder and Contents

Vadim;

In a SharePoint Designer, there is a path and I can trim like you said to get the folder.  I was hoping there is something similar I can use with NINTEX.  The source is a list and not a document library.  When I get ItemURL, it is the list item ID like:

/Lists/Test1/DispForm.aspx?ID=4

Even if there is a folder.  I am using SP2013 and NINTEX is upgraded to 2013 version, on-premise.

Albert

Friday, November 21, 2014 8:44:44 AM
Albert Reilingh
Gravatar

re: Nintex Workflow - Copying a Document Library Folder and Contents

Vadim;

I am using the Query List and am able to return the list of folders in my list.  I trim the URL with substring and get the folder name.  This is what you recommended and it is now working, but I only get the first folder.  Every time I put a filter on, I get no results.  I am trying to put a filter that will return the current folder.  A quick hint and I might have a touch down.  Thanks.

Albert

Friday, April 6, 2018 10:38:18 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

This is what I'm looking for I am using O365. Is there a wsp for this?  In O365 the web request has method options of Get, Post, Put, Soap 1.1, Soap 1.2 and Other. Which do I use to put in the method. Also can you place the xml code that is inside the body of the web request so that we can copy/paste it if the O365 WF is not available. 

Will this recreated folders and subfolders and the files that are in the folders?

Thanks so much!

Friday, April 6, 2018 11:41:22 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi Yoav,

you can't download the file from this post and put it into O365.  It's not compatible that way.

So I'd recommend you look at the idea behind this and build out similar logic in Nintex Workflow for O365.

For the web calls, I'd recommend you use SOAP 1.1 or 1.2.

The XML looks like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <CopyIntoItemsLocal xmlns="http://schemas.microsoft.com/sharepoint/soap/">
            <SourceUrl>{WorkflowVariable:textSourceFileURL}</SourceUrl>
            <DestinationUrls>
<string>{WorkflowVariable:textDestinationFileURL}</string>
</DestinationUrls>
        </CopyIntoItemsLocal>
    </soap:Body>
</soap:Envelope>

 

Vadim

Sunday, April 8, 2018 12:27:58 PM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Thank you for providing the CopyIntoItemsLocal Web call. I was wondering if you can also place the GetListItems web call. I typed it in manually (see below). When I use the SOAP 1.1 (which requires the soap action call) then i get an fault error. When I use the SOAP 1.2 (which doesn't require the action call), I get an error "The remote server returned an error: (415) Unsupported Media Type." and "XML content is invalid. Data at the root level is invalid. Line 1, position 1.."

<?xml version=“1.0” encoding=“utf-8”?>
<soap:Envelope xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/”>
     <soap:Body>
        <GetListItems xmlns=“http://schemas.microsoft.com/sharepoint/soap/”>
            <listName>Source Documents/</listName>
            <viewName></viewName>
            <query></query>
            <viewFields></viewFields>
            <rowLimit></rowLimit>
            <queryOptions>
             <QueryOptions>
             <Folder>Source Documents/‍‍{Variable:CollectionFolders}‍/Folder>
             </QueryOptions>
            </queryOptions>
            <webID></webID>
        </GetListItems>
    </soap:Body>
 

Thursday, April 12, 2018 10:41:25 AM

re: Nintex Workflow - Copying a Document Library Folder and Contents

Hi: I have made some progress towards using this issues. I have managed to get a portion of the script to work. However the WF will only work when providing the Global admin credentials. Is there any reason why this is, is there any settings on the site or at the admin center that can be changed to allow these WFs to run on a site collection admin credentials?

Yoav 

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register

Statistics

  • Entries (277)
  • Comments (1769)

Categories