1

I want to read the content of a NotesStream object (COM reference) without using the file system. Thus my intension was to transfer the content into a .NET byte array. My examples are in VB.net because we needed late binding at that time.

The only way I managed to do it is by reading the stream byte by byte (assuming the Position in the stream was set to 0 beforehand):

Dim streamSize As Long = CInt(notesStream.Bytes)
Dim buffer(streamSizes - 1) As Byte

For i = 0 To (streamSize - 1)
    buffer(i) = notesStream.read(1)(0)
Next

This is very very slow compared to using the filesystem (notesStream.Open()).

The other solutions I found all gave me errors, like this 2 examples:

buffer = notesStream.Read(streamSize)

-> error: the object of type "System.Byte[ * ]" cannot be converted to type "System.Byte[]" / Unable To Cast Object Of Type "System.Byte[ * ]" To Type "System.Byte[]"

(without the additional space character between the brackets and the asterisk, but otherwise it wouldn't have benn displayed correctly in this post)

Array.Copy(notesStream.Read(), 0, buffer, 0, streamSize)

-> error: Source array was not long enough. Check srcIndex and length, and the array's lower bounds.

Hexaholic
  • 3,299
  • 7
  • 30
  • 39
Andreas Grimm
  • 195
  • 1
  • 7
  • 1
    if you do `object buffer = notesStream.Read(streamSize)`, what's the returned real type of `buffer`? – Simon Mourier Apr 05 '13 at 13:19
  • it's of type Byte(). If I then go on and use it e.g. in this statement "Using memStream As New MemoryStream(buffer, False)" I again get this exception: the object of type "System.Byte[ * ]" cannot be converted to type "System.Byte[]" – Andreas Grimm Apr 08 '13 at 12:54
  • can you do a `foreach(var byte in buffer)` on this buffer thing? – Simon Mourier Apr 08 '13 at 13:29
  • what would be the source code equivalent in VB.Net (assuming having "Option Infer" set to "On")? .. just to be sure to use the right syntax. Would it be `For Each byte In buffer` (without mentioning the type at all) ? – Andreas Grimm May 14 '13 at 14:56
  • Dim byte as Byte For Each byte In buffer – Simon Mourier May 14 '13 at 15:02
  • yes, I was able to do a foreach over the buffer object. fyi: the code worked also by not using the beforehand 'Dim byte as Byte' (and thus using type inference .. if I'm right on this). – Andreas Grimm May 14 '13 at 15:18
  • Can you try to do this `Dim arr As Array = DirectCast(application.Evaluate(name), Array) `? Does it throw or does it succeed and get back 'something' in arr? – Simon Mourier May 16 '13 at 07:50

0 Answers0