I am running into an odd situation in dealing with Memorystreams. In
my program, I create an in-memory XML document by using XMLTextWriter
pointing to a memorystream. As a quick test I dumped the stream to a
file, but the file is was truncated by 9 bytes. I skipped the
memorystream a wrote directly to a filestream object, everything
appears OK.
I instantiate the memorystream as 0 bytes, when fully loaded the stream
capacity is 131456 bytes.
Any ideas as to why the Memorystream is not including all the data? I
have also tried explicitly setting the size of the stream beyond the
potential size to no avail.
Code snippets:
MemoryStream ms = new MemoryStream(0);
ms.Seek(0,SeekOrigin.Begin);
XmlTextWriter _xwrite = new
XmlTextWriter(ms,System.Text.Encoding.UTF8);
_xwrite.Formatting = Formatting.Indented;
_xwrite.IndentChar = '\x0009';
_xwrite.WriteStartElement("ESDSubnets");
.....
_xwrite.WriteEndElement();
FileStream fs = new
FileStream(@"C:\Temp\ESDLocations.XML",FileMode.Create);
byte[] b = ms.GetBuffer();
fs.Write(b,0,ms.ToArray().Length);
ms.Flush();
_xwrite.Close();
(both these methods appears to lop off 9 bytes)
FileStream fs = new FileStream(filename,filemode.create);
ms.WriteTo(fs);
OR
FileStream fs = new FileStream(filename,filemode.create);
fs.Write(ms.getBuffer(),0,ms.ToArray().Length);
my program, I create an in-memory XML document by using XMLTextWriter
pointing to a memorystream. As a quick test I dumped the stream to a
file, but the file is was truncated by 9 bytes. I skipped the
memorystream a wrote directly to a filestream object, everything
appears OK.
I instantiate the memorystream as 0 bytes, when fully loaded the stream
capacity is 131456 bytes.
Any ideas as to why the Memorystream is not including all the data? I
have also tried explicitly setting the size of the stream beyond the
potential size to no avail.
Code snippets:
MemoryStream ms = new MemoryStream(0);
ms.Seek(0,SeekOrigin.Begin);
XmlTextWriter _xwrite = new
XmlTextWriter(ms,System.Text.Encoding.UTF8);
_xwrite.Formatting = Formatting.Indented;
_xwrite.IndentChar = '\x0009';
_xwrite.WriteStartElement("ESDSubnets");
.....
_xwrite.WriteEndElement();
FileStream fs = new
FileStream(@"C:\Temp\ESDLocations.XML",FileMode.Create);
byte[] b = ms.GetBuffer();
fs.Write(b,0,ms.ToArray().Length);
ms.Flush();
_xwrite.Close();
(both these methods appears to lop off 9 bytes)
FileStream fs = new FileStream(filename,filemode.create);
ms.WriteTo(fs);
OR
FileStream fs = new FileStream(filename,filemode.create);
fs.Write(ms.getBuffer(),0,ms.ToArray().Length);