Questions tagged [textreader]
68 questions
3
votes
4 answers
How do I count the number of bytes read by TextReader.ReadLine()?
I am parsing a very large file of records (one per line, each of varying length), and I'd like to keep track of the number of bytes I've read in the file so that I may recover in the event of a failure.
I wrote the following:
using (TextReader…

Steve Guidi
- 19,700
- 9
- 74
- 90
3
votes
3 answers
Stream TextReader to a File
I have a TextReader object.
Now, I want to stream the whole content of the TextReader to a File. I cannot use ReadToEnd() and write all to a file at once, because the content can be of high size.
Can someone give me a sample/tip how to do this in…

BennoDual
- 5,865
- 15
- 67
- 153
3
votes
2 answers
Why does TextReader.Read return an int, not a char?
Consider the following code ( .Dump() in LinqPad simply writes to the console):
var s = ""; //3 byte code point. 4 byte UTF32 encoded
s.Dump();
s.Length.Dump(); // 2
TextReader sr = new StringReader("");
int i;
while((i = sr.Read()) >= 0)
{
//…

spender
- 117,338
- 33
- 229
- 351
3
votes
2 answers
Redirecting a Stream to a Text Box in real-time
I have got an interesting dilemma where my application can run as a Console App or a Windows Forms App.
Since I do not want to write a shed load of code like this all over my application:
If ( IsConsoleApp() )
{
// process Console input and…

Intrepid
- 2,781
- 2
- 29
- 54
3
votes
1 answer
Implementing ReadKey() on a TextReader
I have a class that accepts input via a TextReader and will allow the class to receive input from either the console or from a text box.
The following is a very basic example of what I'm trying to do:
using System.IO;
class TestReader()
{
…

Intrepid
- 2,781
- 2
- 29
- 54
3
votes
1 answer
Streaming an IEnumerable
I have a list of strings that is being read in from a file and filtered, all of which is happening using the yield mechanisms so that it is lazy. I then need to pass this into a method which takes a TextReader.
Is there anything wrong with this…

Schotime
- 15,707
- 10
- 46
- 75
3
votes
1 answer
C# 2Gb file is 4gb in Ram. Why?
Im reading in a file(this file consists of one long string which is 2gb in length).
This is my function which read all contents of the file into memory and then splits the string and places:
*reader = StreamReader
public List…

Ivan Bacher
- 5,855
- 9
- 36
- 56
2
votes
3 answers
An efficient way to read from a text file into a database table
I have a log file. The file is structured. Each line is delimeted by commas so that it looks like a table. I have to read from this file and transport the content to a database table. I want to treat the first 9 commas as delimeters and the rest…

Mikayil Abdullayev
- 12,117
- 26
- 122
- 206
2
votes
3 answers
C# download file from the web
Is there a way to make the following function work via proxy?
public T[] ReadStream(System.IO.TextReader reader);
I want to be able to proxify the reader instance, so that it could download a file from the web on reading attempts and cache it…

Yippie-Ki-Yay
- 22,026
- 26
- 90
- 148
2
votes
0 answers
Ways to display 200 to 500 Mb worth of text file in c# wpf
Im trying to create application that can display text file of size 200 to 500Mb. I tried using Textbox, with reading file line by line and appending to the Textbox. This takes 30 to 50s for 200Mb of data. Someone gave me an idea to use list of…

Sathish V
- 328
- 1
- 14
2
votes
3 answers
Cannot read from a closed TextReader expeption in asp.net application
I am running an ASP 4.5 application. One one of the pages the user must answer several questions and the push the button to finish the test. My application uses a text file to analyze the users answers. If the user does everything quickly the…

user2080209
- 749
- 3
- 8
- 25
2
votes
3 answers
Read text file C#
private void button1_Click(object sender, EventArgs e)
{
string fileLoc = @"c:\wms.txt";
if (File.Exists(fileLoc))
{
using (TextReader tr = new StreamReader(fileLoc))
{
…

Werner van den Heever
- 745
- 6
- 17
- 40
2
votes
4 answers
What C# class objects acquire unmanaged resources? Is there a list?
I was working on serializing and deserializing a class object using XML when I came across this blog post that shows how to do it on Windows Phone 7 using the isolated storage area. Windows Phone 7 is the platform I am developing for:
In this…

Robert Oschler
- 14,153
- 18
- 94
- 227
2
votes
2 answers
ArgumentOutOfRange exception C#
I am doing my homework and I have to do a program that extends simple letters from a file, like E and F, to continuous productions, given also in the folder, such as E+T E-F etc. Anyway the code shown below gives me an argument out of range…

Cotan Mircea
- 33
- 4
2
votes
1 answer
TextReader class line count
Hello. Recently, I learned about the class TextReader and about how to read a text file.
However, there are some things I don't really understand.
Assuming this is a new object:
TextReader TR = new…

HuMMeR-SI
- 109
- 1
- 10