473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Reading file in Backword dir using BaseStream.Seek()

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 FileStream("D:\\Source.txt", FileMode.Open, FileAccess.Read);// fs1 contains abcd only
StreamReader sr1 = new StreamReader(fs1);
int s1 = sr1.Read();
/*1.*/ s1 = sr1.Read(); // reading 'a' here

sr1.BaseStream.Seek(-2,SeekOrigin.Current);
sr1.DiscardBufferedData();
/*2.*/ s1 = sr1.Read(); // here irrespective to the no of reads which is performing before Seek function the point 2 is giving the ASCII value of 'c'
that means current value is not set.in overall its treating SeekOrigin.Current as SeekOrigin.End
please help me to get out of this prob .
Jan 16 '08 #1
1 1530
epots9
1,351 Expert 1GB
Moved to the .NET Forums where the resident experts can better assist you.

**Moved from Programming Challenges
Jan 16 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Neil Patel | last post by:
I have a log file that puts the most recent record at the bottom of the file. Each line is delimited by a \r\n Does anyone know how to seek to the end of the file and start reading backwards?
2
by: Peder Y | last post by:
Say I have several images, a jpg a gif and a bmp. Now, I want to save these files to a single binary file. I store the images in, say, Image img1, img2, img3; 1) How can I retrieve the size...
4
by: Arif | last post by:
My programs searches the header of input barcode in index file. Get the record position next to Barcode header. Then moves the file pointer of products file to reach that record. My products...
3
by: sbparsons | last post by:
I have a file opened as a FileStream. I have a StreamReader and StreamWriter object opened, referencing the FileStream object. My aim is to read lines from the file until I find the line where...
2
by: Mad Scientist Jr | last post by:
i'm trying to read a file byte by byte (and later alter the data and write it to a 2nd file byte by byte) and running into a problem where it seems to keep reading the same byte over and over again...
2
by: Phil | last post by:
Problem code: using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Diagnostics; namespace Streams { class Program {
2
by: JB | last post by:
I'm trying to read a text file, and store the position of a specified line, and then later seek back to that line and start reading again. I'm using simple code like the following: StreaReader...
5
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a...
1
by: tom thomas | last post by:
Dear sir, i am very new to c# and i request you to... please look into the problem The following is the code(please see the code below:) which i uses to open the binary file,currently it works...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.