473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

BaseStream.Seek(0, SeekOrigin.Begin)

In the code below the two lines marked with ????????????????? do not work
properly.

The line:

inCF.BaseStream.Seek(0, SeekOrigin.Begin); // rewind inCF to
beginning of the file ??????????????????????

does not change the character position inCF.charPos, and the line:

st = inCF.ReadLine(); // read in next line ?????????????????????????

after reading the last line of the text file, will read the first line of
the file again and never returns a null string.

What am I doing wrong?

Other code in the file:

using System;

using System.IO;

using System.Text;

using System.Windows.Forms;

StreamReader inCF = new StreamReader(fName);

public static bool GoToLabel(ref string prSt, ref string st, ref
StreamReader inCF) // do a GoTo statement

{

bool upTo;

string label1;

bool findLabel;

bool byFile = (inCF != null);

string st7 = GetField(ref st);

if ((st7 != "GOTO") && (st7 != "GOUPTO")) return false;

upTo = (st7 != "GOTO");

if (upTo)

{

DelNPBls(ref st, 6);

}

else

{

DelNPBls(ref st, 4);

}

label1 = GetField(ref st);

if (upTo) st = prSt;

LookLabel(ref st, label1, out findLabel);

if (findLabel) return true;

if (!byFile) return true;

if (upTo)

{

inCF.BaseStream.Seek(0, SeekOrigin.Begin); // rewind inCF to
beginning of the file ??????????????????????

}

do

{

st = inCF.ReadLine(); // read in next line ?????????????????????????

if (st == null) break;

DelTabs(ref st);

LookLabel(ref st, label1, out findLabel);

if (findLabel) return true;

MultiID.MuInterrupt();

}

while (!MultiID.muAbort);

return true;

}

-Harry


Nov 16 '05 #1
2 12550
Harry J. Smith wrote:
In the code below the two lines marked with ????????????????? do not work
properly.

The line:

inCF.BaseStream.Seek(0, SeekOrigin.Begin); // rewind inCF to
beginning of the file ??????????????????????

does not change the character position inCF.charPos, and the line:

Call inCF.DiscardBufferedData() after you perform the Seek() operation
so the stream reader does not get stale data from its buffer.

--
mikeb
Nov 16 '05 #2

"mikeb" <ma************@nospam.mailnull.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Harry J. Smith wrote:
In the code below the two lines marked with ????????????????? do not work properly.

The line:

inCF.BaseStream.Seek(0, SeekOrigin.Begin); // rewind inCF to
beginning of the file ??????????????????????

does not change the character position inCF.charPos, and the line:

Call inCF.DiscardBufferedData() after you perform the Seek() operation
so the stream reader does not get stale data from its buffer.

--
mikeb


Thanks Mike, I changed the code to:

inCF.BaseStream.Seek(0, SeekOrigin.Begin); // rewind inCF to beginning of
the file

inCF.DiscardBufferedData(); // Call inCF.DiscardBufferedData() after you
perform the Seek() operation

// so the stream reader does not get stale data from its buffer.

// This from mikeb in news group
microsoft.public.dotnet.languages.csharp 5/14/2004

and it fixed both problems.

-Harry




Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Leaf | last post by:
Greetings, I've been reading with interest the threads here on deadlocking, as I'm finding my formerly happy app in a production environment suddenly deadlocking left and right. It started...
0
by: Daniel Goldman | last post by:
FileStream.Seek(long offset, SeekOrigin origin) BinaryWriter.Seek(int offset, SeekOrigin origin) Why the difference (int vs long offset)? Daniel Goldman Seattle, WA
0
by: Hai Nguyen | last post by:
Hi Everyone I'm building a C# console application. I need to write data from a text file. The text is something look like this "...From a C++ view there's no difference , between an...
11
by: Tiger | last post by:
We can use seek() in the FileStream class,as we know. But I found that seek() is not work correctly in StreamReader. Who can tell me how to use seek() correctly in StreamReader? thanks a lot! I...
2
by: Joan Reddy | last post by:
Can anyone tell me why this code doesn't work for setting the pointer to the begining of a file stream? This is driving me crazy. At the end of Main1, sString2 is the second line of the file, as...
59
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when...
9
by: hstagni | last post by:
I tried to use fseek in a file opened for writing: ------ BEGIN ------- int main() { char c; FILE *fp; fp=fopen("texto", "wb"); putc('a', fp); putc('b', fp);
1
by: Harsh682 | last post by:
hi, i am using a StreamReader to read the file but i need to go back when certain match not found.this is demo code in which i am trying to go back certain positions. FileStream fs1 = new...
3
by: justabeagle | last post by:
In this code, I write two ints to a binary file using Serialization. What I want to do is after writing them, read in only the second int. I should be able to just seek to 4 bytes past the beginning...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.