Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2006

Tip: Looking for answers? Try searching our database.

StreamReader how do I move to BOF?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Johnnie Walker - 21 Oct 2006 19:20 GMT
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.
Scott M. - 21 Oct 2006 19:27 GMT
I believe you have to close and then re-opend the StreamReader.  You
shouldn't have to make a new instance though.

> Hello, I am using StreamReader.ReadLine() to read a text file.
>
[quoted text clipped - 9 lines]
>
> JT.
Johnnie Walker - 21 Oct 2006 19:49 GMT
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.
[quoted text clipped - 12 lines]
> >
> > JT.
Peter Duniho - 21 Oct 2006 21:10 GMT
> 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();
...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.