You can write to the stream by encoding a string containing the information you want to write to a byte array and then using the stream’s Write method to write the byte array to the MemoryStreams.
The Close method also calls Flush internally to commit the data to the data store.
Here are sample Example
C# Example :
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ms.Write(data, 0, data.Length);
VB.net Example :
Dim ms As New System.IO.MemoryStream()
ms.Write(data, 0, data.Length)