I am trying to convert the memory stream generated from richeditDocument to byte array. The code is given below:
Public Sub saveAsTemplate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ms As MemoryStream = New MemoryStream()
richEditControl1.SaveDocument(ms, DocumentFormat.Rtf)
GetStreamAsByteArray(ms)
MessageBox.Show("save")
End Sub
Private Function GetStreamAsByteArray(ByVal stream As MemoryStream) As Byte()
Dim streamLength As Integer = Convert.ToInt32(stream.Length)
Dim fileData As Byte() = New Byte(streamLength) {}
' Read the file into a byte array
stream.Read(fileData, 0, streamLength)
stream.Flush()
stream.Close()
Return fileData
End Function
The stream is generated as I can get the stream length, however the final bite array only consist of 0's making it invalid. How can I get correct byte array of it?