我試圖將從richeditDocument生成的內存流轉換爲字節數組。代碼如下:在VB.Net中將MemoryStream轉換爲Byte Array
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
流生成,因爲我可以得到流的長度,但最終的咬合數組只包含0使其無效。我怎樣才能得到正確的字節數組呢?