Copy.GetItem Method

Generates a Byte array representation of a document that can be passed to the CopyIntoItems method to copy the document to a different server.

Namespace:  [Copy Web service]
Web service reference: http://Site/_vti_bin/Copy.asmx

Syntax

'Declaration
<SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/GetItem", RequestNamespace := "http://schemas.microsoft.com/sharepoint/soap/",  _
    ResponseNamespace := "http://schemas.microsoft.com/sharepoint/soap/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function GetItem ( _
    Url As String, _
    <OutAttribute> ByRef Fields As FieldInformation(), _
    <OutAttribute> ByRef Stream As Byte() _
) As UInteger
'Usage
Dim instance As Copy
Dim Url As String
Dim Fields As FieldInformation()
Dim Stream As Byte()
Dim returnValue As UInteger

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

Parameters

  • Url
    Type: System.String

    A String that contains the absolute source (on the server to which the SOAP request is sent) of the document that is to be retrieved.

  • Fields
    Type: []

    An array of FieldInformation objects, passed as an out parameter, that represent the fields and the corresponding field values that can be copied from the retrieved document.

  • Stream
    Type: []

    An array of Bytes, passed as an out parameter, that is a base-64 representation of the retrieved document's binary data.

Return Value

Type: System.UInt32
A UInt32 that returns 0 to indicate that the operation has completed. (There are also two out parameters containing an array of CopyResult objects and an array of FieldInformation 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.

Examples

The following example copies a document from one server running Microsoft SharePoint Foundation 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