I'm using the OpenCMIS dotCMIS library to read documents from CMIS-compliant repositories.
I have parallel Java/Chemistry and VB.Net/dotCMIS test programs talking to the same FileNet fncmis repository.
I can connect, query, fetch the documents OK, in either Java or VB.Net.
PROBLEM: In VB.Net, I can only read content from the first document. The second and subsequent documents give me a content stream ... but I get exactly zero bytes. Java works fine. VB.Net fails after the first document.
There are no compile warnings or runtime exceptions.
QUESTION: Can you see any reason subsequent calls to DisplayDocument()
would have zero bytes?
I'm using the latest version of dotCMIS, Release 0.7.
Option Explicit On
Imports DotCMIS.Client
Imports DotCMIS.SessionParameter
...
Public Sub DisplayDocument(ByVal document As IDocument)
...
' Open stream to document content and copy to a file
Dim contentStream As DotCMIS.Data.IContentStream = document.GetContentStream()
sFilePath = "c:\temp\" & contentStream.FileName
Using fis = contentStream.Stream
Using fos = New System.IO.FileStream(sFilePath, IO.FileMode.OpenOrCreate)
Dim buffer(2048) As Byte
Do While (i = fis.Read(buffer, 0, buffer.Length) > 0)
fos.Write(buffer, 0, i)
Loop
End Using
End Using
...
Problem resolved!
In retrospect, it had nothing to do with OpenCMIS and everything to do with .Net streams: I simply forgot to specify IO.FileAccess.Write
when I opened the .Net output stream.
Here is the corrected code:
' Open stream to document content and copy to a file
Dim contentStream As IContentStream = document.GetContentStream()
sFilePath = "c:\temp\" & contentStream.FileName
Using fis = contentStream.Stream
Using fos = New System.IO.FileStream(sFilePath, IO.FileMode.Create, IO.FileAccess.Write)
Dim buffer(2048) As Byte
Do
i = fis.Read(buffer, 0, buffer.Length)
If i > 0 Then fos.Write(buffer, 0, i)
Loop While i > 0
End Using
End Using