Hi Yehia,
You might want to try loading the xml file into an XmlDocument instead of parsing it multiple times using a reader.
But if you want to use a MemoryStream then here's some code:
string file = @"C:\file.xml";
// .NET 2.0
byte[] bytes = System.IO.File.ReadAllBytes(file);
/* .NET 1.*
byte[] bytes = null;
using (System.IO.FileStream fileStream = new System.IO.FileStream(
file, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
System.IO.BinaryReader reader = new System.IO.BinaryReader(fileStream);
bytes = reader.ReadBytes((int) fileStream.Length);
}
*/
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes))
{
System.Xml.XmlTextReader reader = System.Xml.XmlTextReader.Create(stream);
...
}
--
Dave Sexton
"Yehia A.Salam" <ye*****@hotmail.comwrote in message news:7A**********************************@microsof t.com...
Hello,
I am trying to read from an xml file and put it to a memory stream so I can read it multiple times from the beginning using
XmlTextReader without accessing the harddisk , I tried using FileStream but it locked the xml file so I can't access it anymore
until I close the filestream, so my question is how to read from the file to the memorystream directly or read to the filestream
first and the copy it to the memorystream?
Thanks
Yehia