Uploading Files to the Prolog Document Management System (or File Management System MS)

In order to upload a file(s) to the Prolog Document Management System (DMS), you must invoke three web methods in a specified sequence:

  1. BeginUploadFile
  2. UploadFileChunk
  3. EndUploadFile or EndQuickUpload

To upload a file to the Prolog DMS:

Code Example:

The following example assumes you have the FileService proxy class named FileService created in the visual studio project.

Public Function UploadFile(ByVal maxChunkSize As Integer, _
	ByVal fileName As String, _
	ByVal documentTypeName As String, _
	ByVal documentGuid As String) As Boolean 

	' Create a fileservice
	Dim fileManagementProxy As New WebServices.FileManagement.FileService()
	ProxyHelper.SetupPrologConnectProxy(fileManagementProxy, _
			String.Format("http://{0}/Prolog/Connect/fileService.asmx", MyHostName), _
			MyPrologUserName, MyPrologPassword, MyPortfolioName, MyProjectName)
	' First: create an upload session ID
	Dim uploadSessionId As String = fileManagementProxy.BeginUploadFile()
	Dim fileContent As Byte() = ReadFile(fileName)
            
	Dim uploadChunk(Math.Min(fileContent.Length - 1, maxChunkSize)) As Byte 
            
		Try
		Dim remainingLength As Integer = fileContent.Length
		Dim sourceOffset As Integer = 0
		Do 
			Array.Resize(uploadChunk, Math.Min(remainingLength - 1, maxChunkSize))
			Buffer.BlockCopy(fileContent, sourceOffset, uploadChunk, 0, uploadChunk.Length)
				' Second: start uploading the file by chunk
			fileManagementProxy.UploadFileChunk(uploadSessionId, uploadChunk)
			sourceOffset += maxChunkSize
				remainingLength -= uploadChunk.Length
		Loop while sourceOffset < fileContent.Length 
                
		' Third: end the upload, commit the file creation and link to Prolog document record
		fileManagementProxy.EndQuickUpload(uploadSessionId, fileName, documentTypeName, documentGuid)
		Return True 
		Catch ex as exception
		' Cancel the upload
		fileManagementProxy.CancelUploadFile(uploadSessionId)
		Return False 
	End Try
End Function


''' Read file into byte array
Private Function ReadFile(filename As String) As Byte()

	Dim fs As New FileStream(filename, FileMode.Open, FileAccess.Read)
	Dim FileData As Byte() = New Byte(Convert.ToInt32(fs.Length - 1)) {}
	fs.Read(FileData, 0, System.Convert.ToInt32(fs.Length))
	fs.Close()
	Return FileData
	        
End Function