Uploads a new document or creates a new version of an existing document in byte array format to the specified path - UploadDocument3 - Alternate of the original method

Syntax

Visual Basic (declaration)
Public Function UploadDocument3( _ 
ByVal AuthenticationTicket as String, _ ByVal Path as String, _ ByVal FileContent as Byte(), _ ByVal VersionComment as String, _ ByVal Checkout as bool) as XmlNode

C# (declaration)
public XmlNode UploadDocument3( 
string AuthenticationTicket, string Path, byte[] FileContent, string VersionComment, bool Checkout)

Parameters

AuthenticationTicket
    string inforouter ticket
Path
    string An infoRouter document path that to be created or updated
FileContent
    byte[] The Content of the file. The Content must be in the format of the byte array.
VersionComment
    string The comments of the author for the uploaded document.
Checkout
    bool Checks out if required.

Return Value

returns xml fragment.
<response success="true" error="">
if success = "true", the document has been uploaded.
if success = "false", the error attribute returns the error description.

Remarks

The caller must have at least "Add" permissions on the folder.
If the specified path does not exist, the path will be created.
If a document with the same name already exists in the same path, a new version of the existing document will be created.
This method is usefull when the documents are relatively small.
Instead of this function use UploadDocumentwWithHandler method for large files.

minus gif Example

Visual Basic Example
Option Explicit On
Option Strict On

Module Module_UploadDocument3

    Sub UploadDocument3(ByVal ServiceURL As String, ByVal AuthenticationTicket As String)

        Const uploadpath As String = "/TestDomain/sample/s.doc"
        Const LocalFilePath As String = "c:\temp\SummerPlan.doc"
        Dim VersionComment As String = "Lorem dolor sit amet line 1....." + Environment.NewLine + _
                                       "Lorem dolor sit amet line 2....." + Environment.NewLine + _
                                       "Lorem dolor sit amet line 3....."
        Const CheckoutFlag As Boolean = True

        Dim IR_OBJ As InfoRouter.srv

        Try
            If System.IO.File.Exists(LocalFilePath) Then
                Dim FileName As String = System.IO.Path.GetFileName(LocalFilePath)
                Dim buffer() As Byte

                IR_OBJ = New InfoRouter.srv
                IR_OBJ.Url = ServiceURL

                'create byte array to upload
                Dim fs As System.IO.FileStream = New System.IO.FileStream(LocalFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
                Dim br As System.IO.BinaryReader = New System.IO.BinaryReader(fs) ' create a BinaryReader
                buffer = br.ReadBytes(Convert.ToInt32(fs.Length))
                br.Close()
                fs.Close()
                br = Nothing
                fs = Nothing

                'call upload method
                Dim xml_response As System.Xml.XmlNode = IR_OBJ.UploadDocument3(AuthenticationTicket, uploadpath, buffer, VersionComment, CheckoutFlag)

                'check response xml if any error occured.
                If xml_response.Attributes("success").Value.ToUpperInvariant() = "TRUE" Then
                    Console.WriteLine("The Document has been uploaded successfully.")
                Else
                    Console.WriteLine("The Document cannot be uploaded.")
                    Console.WriteLine("ERROR:" & xml_response.Attributes("error").Value)
                End If
                xml_response = Nothing
            Else
                Console.WriteLine("ERROR:Local file not found.")
            End If
        Catch ex As Exception
            Console.WriteLine("ERROR:" + ex.Message)
        Finally
            IR_OBJ = Nothing
        End Try
    End Sub

End Module