PROBLEM MOVING FILE POINTER

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

Guest

Following are my text file(IndxItms.txt) contents:
---------------------------------------------------
0000 0
0002 52
0020 260
0045 312
0051 364
0087 416


my C# code:
----------
StreamWriter sr_IndxItms = File.OpenText("\\My Documents\\IndxItms.txt");

MessageBox.Show(this.sr_IndxItms.ReadLine()); //output=> 0000 0

this.sr_IndxItms.BaseStream.Position = 0;
MessageBox.Show(this.sr_IndxItms.ReadLine()); //output=> 0002 52

this.sr_IndxItms.BaseStream.Seek(0, SeekOrigin.Begin);
MessageBox.Show(this.sr_IndxItms.ReadLine()); //output=> 0020 260


my question:
-----------

after statements:

this.sr_IndxItms.BaseStream.Position = 0;
or
this.sr_IndxItms.BaseStream.Seek(0, SeekOrigin.Begin);

file pointer must move to start of the file, but the output showing that
file pointer is not moving to start of the file,
instead reading from it's current position.

Why this is not workig? How can I move file pointer to the start of file?

Arif.
 
Hi all,

problem solved. i have to call
this.sr_IndxItms.DiscardBufferedData();
to discard the buffered data before reading.

Arif.
 
Back
Top