I have written a routine that accepts as a parameter a System.IO.TextWriter, this is then used to create a System.Xml.XmlTextWriter and I proceed to write some Xml content to the stream using the XmlTextWriter. When I pass in a System.IO.StringWriter this works well and I can display the Xml content.
I now want to encrypt the Xml, therefore I have created a System.IO.MemoryStream, then I use this to create a System.IO.StreamWriter which I pass into my routine that creates the Xml. The problem is that only 1024 bytes (1Kb) seem to be written to the stream. I have tried creating the stream with a capacity of 102400 (100Kb) however only 1Kb is written. I have also tried setting the length of the stream to 100Kb, still only 1Kb is written and the 1025th byte in the stream is 0.
Here is a quick example of my code:
Code:
' Create a MemoryStream with a capacity of 100Kb
Dim myStream As New MemoryStream(102400)
' Use this MemoryStream to create a StreamWriter
Dim myWriter As New StreamWriter(myStream)
' Call the MakeXml routine and pass in the StreamWriter
MakeXml(myWriter)
' Use the MemoryStream to create a StreamReader
Dim myReader As New StreamReader(myStream)
' Read to the end of the StreamReader placing the data into a text box
Text1.Text = myReader.ReadToEnd
And here is an example of the code in the MakeXml() routine:
Code:
Public Sub MakeXml(ByRef s As TextWriter)
Code:
Dim XmlWriter As New System.Xml.XmlTextWriter(s)
With XmlWriter
.WriteStartDocument()
.WriteStartElement("Book")
.WriteAttributeString("Title", "Pro VB.NET")
' Lots more calls to write some Xml content...
.WriteEndElement()
.WriteEndDocument()
End With
End Sub
What do I have to do to write more than 1Kb to the MemoryStream? What am I doing wrong?
Regards
Owain Williams