Setting file position in Streamreader

bhi

New member
Joined
Jan 29, 2004
Messages
2
I want to set the file pointer again after storing a determined position.

Sample:

If strReturnvalue = "Start Section" And Not blnSectionstarted Then
intOffset = sr.BaseStream.Position
blnSectionstarted = True
xtw.WriteStartElement("CompSection")
End If
If strReturnvalue = "End Section" And blnSectionstarted Then
blnSectionstarted = False
xtw.WriteEndElement()
End If
If (intPrevious = -1 And intRecord <> -1) Or (intPrevious <> -1 And intRecord <> -1 And intRecordPointer <> 11) Then
If blnSectionstarted Then
xtw.WriteElementString("ComponentLine", strPrevious)
Else
xtw.WriteElementString("Tekst", strPrevious)
End If
strPrevious = strRule
Else
strPrevious = strPrevious & strRule
End If
intPrevious = intRecord
End If
Loop
sr.BaseStream.Seek(intOffset, SeekOrigin.Begin)
intOffset = sr.BaseStream.Position
strCurrent = sr.ReadLine

The intOffset stores the position which is later used in the basestream.seek method. The position is set, however the strCurrent = sr.Readline retrieves a string as if the sr.basestream.seek has never been done.

Please help me out to shift back in position reading a simple text file.

Thanks.
 
Cant you just read the line into strCurrent (or into some other string variable) at that point where you tried to set intOffset to the basestream position, so that you wont have to try to go back.
 
Because of this truncation of code the problem is somehow not
clear. I want to be able to go back and forth in this text file on
the basis of certain data I retrieve from this text file. Because the file stream is in memory I should be able to do this.
I could also read the file into an entire array to solve this problem.
However I dont want to build a solution which should be functional there according Microsoft.
 
Back
Top