cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Copy a file from a doc library to another doc library in another subsite

Jump to solution

Hi,

I would like to copy i file from a doc library to another but the library destination is in another sub site.

Anyone could help me please.

Thanks

0 Kudos
Reply
6 Replies
Highlighted
Community Manager Community Manager
Community Manager

Re: Copy a file from a doc library to another doc library in another subsite

Jump to solution

So while I would say just use a send to destination (OOTB SharePoint), you can also check out this post by Vadim Tabakman‌  http://www.vadimtabakman.com/nintex-workflow-move-documents-and-preserve-version-history.aspx

Reply
Workflow Hero

Re: Copy a file from a doc library to another doc library in another subsite

Jump to solution

Hi Wissem.

You can use WebServices for this. I have used this in past and has worked.

Web Service: Copy.asmx

Web Method: CopyIntoItems (Note: you can also use CopyIntoLocal mentod. I did not use it as I had to update some dynamic metadata when copying the item)

Specify your destination url in the SOAP Editor. I used the complete url for the documents like:

site\library\document.fileextension

and for Stream use the following:

<mSmiley Frustratedtream>[FileData]</mSmiley Frustratedtream>

Try this for more information: http://msdn.microsoft.com/en-us/library/copy.copy.copyintoitems(v=office.12).aspx

Hope this helps,

Mandeep

Reply
Workflow Hero

Re: Copy a file from a doc library to another doc library in another subsite

Jump to solution

I've used the solution Eric Harris‌ suggested a lot. Works well for me.

Reply
Not applicable

Re: Copy a file from a doc library to another doc library in another subsite

Jump to solution

Hi Mandeep,

I have tried to use the CopyIntoItems method you've suggested. Looking at the MSDN link you've provided and associated examples, I've built SourceUrl and DestinationUrl, but haven't been able to get it to work.

To put it precisely, here is the syntax of SOAP Editor:

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://schemas.microsoft.com/sharepoint/soap/">

  <soap:Header>

  </soap:Header>

  <soap:Body>

    <m:CopyIntoItems>

      <mSmiley FrustratedourceUrl>http://sp2013found/projekti/Lists/Projekti/Attachments/76/ProjectPlan.mpp</mSmiley FrustratedourceUrl>

      <mSmiley Very HappyestinationUrls>

        <m:string>http://sp2013found/projekti/Shared%20Documents/Forms/AllItems.aspx?RootFolder=%2Fprojekti%2FShared%2...</m:string>

      </mSmiley Very HappyestinationUrls>

      <m:Fields>

        <m:FieldInformation Type="File" DisplayName="string" InternalName="string" Value="string">

        </m:FieldInformation>

      </m:Fields>

      <mSmiley Frustratedtream>base64Binary</mSmiley Frustratedtream>

    </m:CopyIntoItems>

  </soap:Body>

</soap:Envelope>

And here is the error result:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <soap:Body>

    <CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">

      <CopyIntoItemsResult>0</CopyIntoItemsResult>

      <Results>

        <CopyResult ErrorCode="Unknown" ErrorMessage="The file or folder name &quot;http://sp2013found/projekti/Shared Documents/Forms/AllItems.aspx?RootFolder=/projekti/Shared Documents/projekt77/1 Pokretanje&quot; contains invalid characters. Please use a different name. Common invalid characters include the following: # % &amp; * : &lt; &gt; ? /  { | }" DestinationUrl="http://sp2013found/projekti/Shared%20Documents/Forms/AllItems.aspx?RootFolder=%2Fprojekti%2FShared%2..." />

      </Results>

    </CopyIntoItemsResponse>

  </soap:Body>

</soap:Envelope>

I presume there is an error in the definition of DestinationUrl. But which character in invalid here? Perhaps question mark? But that isn't XML special character, is it?

Also, I've tried to replace all / with %2F and spaces with %20; and vice versa, but the errors kept appearing.

Hopefully, the answer is probably obvious for an XML expert. Please assist.

...

Alternatively, if I am to use Stream:

- How do I populate that array? By using Copy.GetItem method perhaps?

If so, could I use an absolute URL as a GetItem input parameter?

What would be the type of the GetItem output? mSmiley Frustratedtream + variable of which type?

- Then I would pass the stream to the CopyIntoItems method to copy the array into a library on DestinationUrl?

Thanks, best regards!

Ivan

Reply
Workflow Hero

Re: Copy a file from a doc library to another doc library in another subsite

Jump to solution

Remarks

https://msdn.microsoft.com/en-us/library/copy.copy.copyintoitems(v=office.12).aspx#Anchor_1


Use the GetItem method to generate a Byte array of the document, and then pass it as the Stream parameter to the CopyIntoItems method to copy the array into a document on the destination server.

SourceUrl is not used in the copy operation but is stored with the document on the server as the CopySource property. This enables users of the copy to navigate back to the source.

It means your SOAP cannot simply contains       <mSmiley Frustratedtream>base64Binary</mSmiley Frustratedtream>   you should replace the "base64Binary" by the stream of the document (some similar to <Stream>/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMTEhUSExMWFRUXGB8XGBcXGBgYGBsXGBcdGhceIBoYHyggGx0lHRgXITEiJSkrLi4uGB8zODMtNygtLi0BCgoKDg0OFQ8QFy0ZHR0tLS0tLSstLSsrLSstLS0tLS0rKy0tKystLS0tLSstKystLS0tLS0tLS0rLS0rLSstK//AABEIAOEA4QMBIgACEQEDEQH/xAAcAAEAAgMBAQEAAAAAAAAAAAAABQYDBAcIAgH/xABIEAACAQIEAgUIBggEBAcAAAABAgMAEQQFEiEGMRMiQVFhBxQycYGRodEjQlKCscEVM1NicpKT8GOy0uFDRFTCJDRVc6Kz8f/EABYBAQEBAAAAAAAAAAAAAAAAAAABAv....</mSmiley Frustratedtream>

I hope it helps

Best regards,

0 Kudos
Reply
Not applicable

Re: Copy a file from a doc library to another doc library in another subsite

Jump to solution

What do you mean by [FileData] ? I used 'base64binay' but it corrupts the file at the destination.

0 Kudos
Reply