Hello, I am using StreamReader.ReadLine() to read a text file.

I need a way to move the "pointer" back to the BOF (Beginning of File)
without having to close the object and create a new instance.

Is there any way of doing this? or is there another class within the
framework that will allow me to achieve this?

Any thoughts/ideas would be greatly appreciated

Thanks

JT.

Re: StreamReader how do I move to BOF? by Scott

Scott
Sat Oct 21 13:27:09 CDT 2006

I believe you have to close and then re-opend the StreamReader. You
shouldn't have to make a new instance though.


"Johnnie Walker" <tregoning@gmail.com> wrote in message
news:1161454851.109879.275610@i3g2000cwc.googlegroups.com...
> Hello, I am using StreamReader.ReadLine() to read a text file.
>
> I need a way to move the "pointer" back to the BOF (Beginning of File)
> without having to close the object and create a new instance.
>
> Is there any way of doing this? or is there another class within the
> framework that will allow me to achieve this?
>
> Any thoughts/ideas would be greatly appreciated
>
> Thanks
>
> JT.
>



Re: StreamReader how do I move to BOF? by Johnnie

Johnnie
Sat Oct 21 13:49:08 CDT 2006

Not too sure of how do I re-open the StreamReader....

do you mean this?:

TextReader tr = new StreamReader("c:\\test.txt");
tr.ReadLine() //read line 1
tr.ReadLine() //read line 2
tr.close();
tr = new StreamReader("c:\\test.txt");
tr.ReadLine() //read line 1

If that's what you mean I think I am still creating a new instance
though

Cheers

JT.



> I believe you have to close and then re-opend the StreamReader. You
> shouldn't have to make a new instance though.
>
>
> "Johnnie Walker" <tregoning@gmail.com> wrote in message
> news:1161454851.109879.275610@i3g2000cwc.googlegroups.com...
> > Hello, I am using StreamReader.ReadLine() to read a text file.
> >
> > I need a way to move the "pointer" back to the BOF (Beginning of File)
> > without having to close the object and create a new instance.
> >
> > Is there any way of doing this? or is there another class within the
> > framework that will allow me to achieve this?
> >
> > Any thoughts/ideas would be greatly appreciated
> >
> > Thanks
> >
> > JT.
> >


Re: StreamReader how do I move to BOF? by Peter

Peter
Sat Oct 21 15:10:08 CDT 2006

"Johnnie Walker" <tregoning@gmail.com> wrote in message
news:1161454851.109879.275610@i3g2000cwc.googlegroups.com...
> Hello, I am using StreamReader.ReadLine() to read a text file.
>
> I need a way to move the "pointer" back to the BOF (Beginning of File)
> without having to close the object and create a new instance.

Haven't tried this myself, but I think this should work:

StreamReader sr;
...
sr.BaseStream.Seek(0, SeekOrigin.Begin);
sr.DiscardBufferedData();
...