The difference between these 2 techniques in open xml file ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I am just curious, is there any difference between these 2 techniques used
as below:

1.

FileStream fs = new FileStream(@"C:\hello.xml", FileMode.Open);
XmlTextReader xmlreader = new XmlTextReader(fs);

2.

XmlTextReader xmlreader = new XmlTextReader(@"C:\hello.xml");

Any help?

Cheers.
 
HI Chua
First to say , FileStreams buffer input and output which help
improve performance. Also what you can with file streams in .net it gives
you the built in asynchronous call option as you can issue an
asynchronous read or asynchronous write on the file using the beginRead
and beginWrite method .
In your case you can use that if you know that loading the file to the
reader would take a while and you don't want the UI , forexample, to block
while the lading of the reader, what can be caused by the statement
XmlTextReader xmlreader = new XmlTextReader(@"C:\hello.xml"); and would not
happen if you are to use a begin read instead
One other thing is that streams allow random access for sure to the file
with the seek method ( thought most files allow that , you will not be sure
however ).
Hope this helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
fundementally the second uses the first under the covers.

However, the second demonstrates that you can hook an XmlTextReader on to any stream not just a file stream - so a network stream for example or a memory stream

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi there,

I am just curious, is there any difference between these 2 techniques used
as below:

1.

FileStream fs = new FileStream(@"C:\hello.xml", FileMode.Open);
XmlTextReader xmlreader = new XmlTextReader(fs);

2.

XmlTextReader xmlreader = new XmlTextReader(@"C:\hello.xml");

Any help?

Cheers.
 
Back
Top