Copy.CopyIntoItems Method

Copies a document represented by a Byte array to one or more locations on a server.

Web Service: CopyWeb Reference: http://<Site>/_vti_bin/Copy.asmx

Syntax

<SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems", RequestNamespace:="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace:="http://schemas.microsoft.com/sharepoint/soap/", Use:=SoapBindingUse.Literal, ParameterStyle:=SoapParameterStyle.Wrapped)> _
Public Function CopyIntoItems ( _
    SourceUrl As String, _
    DestinationUrls As String(), _
    Fields As FieldInformation(), _
    Stream As Byte(), _
    <OutAttribute> ByRef Results As CopyResult() _
) As UInteger

Dim instance As Copy
Dim SourceUrl As String
Dim DestinationUrls As String()
Dim Fields As FieldInformation()
Dim Stream As Byte()
Dim Results As CopyResult()
Dim returnValue As UInteger

returnValue = instance.CopyIntoItems(SourceUrl, DestinationUrls, Fields, Stream, Results)
[SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public uint CopyIntoItems (
    string SourceUrl,
    string[] DestinationUrls,
    FieldInformation[] Fields,
    byte[] Stream,
    out CopyResult[] Results
)

Parameters

  • SourceUrl
    A String that contains the absolute source URL of the document to be copied.
  • DestinationUrls
    An array of Strings that contain one or more absolute URLs specifying the destination location or locations of the copied document.
  • Fields
    An array of FieldInformation objects that define and optionally assign values to one or more fields associated with the copied document.
  • Stream
    An array of Bytes that contain the document to copy using base-64 encoding.
  • Results
    An array of CopyResult objects, passed as an out parameter.

Return Value

A UInt32 that returns 0 to indicate that the operation has completed. (There is also an out parameter containing an array of CopyResult objects.)

Remarks

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.

Example

The following example copies a document from one server running Windows SharePoint Services to two locations on a different server.

Dim myCopyService As New Web_Reference_Name.Copy()
myCopyService.Credentials = _
    System.Net.CredentialCache.DefaultCredentials

Dim copySource As String = _
    "http://Server1/Site1/Shared Documents/test.txt"
Dim copyDest As String() = _
    {"http://Server2/Site1/Shared Documents/test.txt", _
    "http://Server2/Site2/Shared Documents/test.txt"}

Dim myFieldInfo As New Web_Reference_Name.FieldInformation
Dim myFieldInfoArray As Web_Reference_Name.FieldInformation() = {myFieldInfo}
Dim myByte As Byte
Dim myByteArray() As Byte = {myByte}

Dim myGetUint As System.UInt32 = _
    myCopyService.GetItem(copySource, myFieldInfoArray, myByteArray)

Dim myCopyResult1 As New Web_Reference_Name.CopyResult()
Dim myCopyResult2 As New Web_Reference_Name.CopyResult()
Dim myCopyResultArray As Web_Reference_Name.CopyResult() = _
    {myCopyResult1, myCopyResult2}

Try
    Dim myCopyUint As System.UInt32 = _
        myCopyService.CopyIntoItems(copySource, copyDest, _
        myFieldInfoArray, myByteArray, myCopyResultArray)
    If myCopyUint = 0 Then
        Dim idx As Integer = 0
        Dim myCopyResult As Web_Reference_Name.CopyResult
        For Each myCopyResult In myCopyResultArray
            Dim opString As String = (idx + 1).ToString()
            If myCopyResultArray(idx).ErrorMessage Is Nothing Then
                MessageBox.Show(("Copy operation " + opString + _
                    "completed." + ControlChars.Cr + _
                    ControlChars.Lf + "Destination: " + _
                    myCopyResultArray(idx).DestinationUrl))
            Else
                MessageBox.Show(("Copy operation " + opString + _
                    "failed." + ControlChars.Cr + _
                    ControlChars.Lf + "Error: " + _
                    myCopyResultArray(idx).ErrorMessage + _
                    ControlChars.Cr + ControlChars.Lf + "Code: " + _
                    myCopyResultArray(idx).ErrorCode))
            End If
            idx += 1
        Next myCopyResult
    End If
Catch exc As Exception
    Dim idx As Integer = 0
    Dim myCopyResult As Web_Reference_Name.CopyResult
    For Each myCopyResult In myCopyResultArray
        idx += 1
        If myCopyResult.DestinationUrl Is Nothing Then
            Dim idxString As String = idx.ToString()
            MessageBox.Show("Copy operation " + idxString + _
                " failed." + ControlChars.Cr + ControlChars.Lf + _
                "Description: " + exc.Message, "Exception", _
                MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    Next myCopyResult
End Try
Web_Reference_Name.Copy myCopyService = new Web_Reference_Name.Copy();
myCopyService.Credentials = 
    System.Net.CredentialCache.DefaultCredentials;

string copySource = "http://Server1/Site1/Shared Documents/test.txt";
string[] copyDest = { "http://Server2/Site1/Shared Documents/test.txt", 
    "http://Server2/Site2/Shared Documents/test.txt" };

Web_Reference_Name.FieldInformation myFieldInfo = new 
    Web_Reference_Name.FieldInformation();
Web_Reference_Name.FieldInformation[] myFieldInfoArray = { myFieldInfo };
byte[] myByteArray;

uint myGetUint = myCopyService.GetItem(copySource, 
    out myFieldInfoArray, out myByteArray);

Web_Reference_Name.CopyResult myCopyResult1 = new Web_Reference_Name.CopyResult();
Web_Reference_Name.CopyResult myCopyResult2 = new Web_Reference_Name.CopyResult();
Web_Reference_Name.CopyResult[] myCopyResultArray = { myCopyResult1, 
    myCopyResult2 };

try
{
    uint myCopyUint = myCopyService.CopyIntoItems(copySource, copyDest, 
        myFieldInfoArray, myByteArray, out myCopyResultArray);
    if (myCopyUint == 0)
    {
        int idx = 0;
        foreach (Web_Reference_Name.CopyResult myCopyResult in myCopyResultArray)
        {
            string opString = (idx+1).ToString();
            if (myCopyResultArray[idx].ErrorMessage == null)
            {
                MessageBox.Show("Copy operation " + opString + 
                    "completed.\r\n" + "Destination: " + 
                    myCopyResultArray[idx].DestinationUrl);
            }
            else
            {
                MessageBox.Show("Copy operation " + opString + 
                    " failed.\r\n" + "Error: " + 
                    myCopyResultArray[idx].ErrorMessage + "\r\n" +
                    "Code: " + myCopyResultArray[idx].ErrorCode);
            }
            idx++;
        }
    }
}
catch (Exception exc)
{
    int idx = 0;
    foreach (Web_Reference_Name.CopyResult myCopyResult in myCopyResultArray)
    {
        idx++;
        if (myCopyResult.DestinationUrl == null)
        {
            string idxString = idx.ToString();
            MessageBox.Show("Copy operation " + idxString + 
                " failed.\r\n" + "Description: " + exc.Message,
                "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}

See Also

Reference

Copy Class
Copy Members
Copy Web Service