Questions tagged [textreader]
68 questions
146
votes
6 answers
In C#, how can I create a TextReader object from a string (without writing to disk)
I'm using A Fast CSV Reader to parse some pasted text into a webpage. The Fast CSV reader requires a TextReader object, and all I have is a string. What's the best way to convert a string into a TextReader object on the fly?
Thanks!
Update-
Sample…

Hairgami_Master
- 5,429
- 10
- 45
- 66
23
votes
5 answers
Sharing violation IOException while reading and writing to file C#
Here is my code:
public static TextWriter twLog = null;
private int fileNo = 1;
private string line = null;
TextReader tr = new StreamReader("file_no.txt");
TextWriter tw = new StreamWriter("file_no.txt");
line = tr.ReadLine();
if(line != null){
…

Ozg
- 391
- 2
- 7
- 20
12
votes
3 answers
How to loop over lines from a TextReader?
How do I loop over lines from a TextReader source?
I tried
foreach (var line in source)
But got the error
foreach statement cannot operate on variables of type 'System.IO.TextReader' because 'System.IO.TextReader' does not contain a public…

Colonel Panic
- 132,665
- 89
- 401
- 465
11
votes
1 answer
Why does IEumerator affect the state of IEnumerable even the enumerator never reached the end?
I am curious why the following throws an error message (text reader closed exception) on the "last" assignment:
IEnumerable textRows = File.ReadLines(sourceTextFileName);
IEnumerator textEnumerator =…

Matt
- 7,004
- 11
- 71
- 117
8
votes
4 answers
TextReader.Peek behaviour and detecting end of stream/reader
When I'm using a Text reader what is the best way to detect that I am actually at the end of my data? The usual way to do this is something like the following,
while(reader.Peek() != -1)
{
///do stuff
}
However the msdn…

Colin Bull
- 959
- 7
- 15
7
votes
1 answer
What is the difference between Read() and ReadBlock() calls on TextReader?
The title more or less says it all. The calls are documented:
Here for TextReader.Read Method (Char[], Int32, Int32)
and
Here for TextReader.ReadBlock() with the same argument types.
I want to extract a portion of a byte array, for which I make up…

Marcel
- 15,039
- 20
- 92
- 150
6
votes
2 answers
How to open a StreamReader in ShareDenyWrite mode?
How do i open a StreamReader with FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_DELETE?
Same question, slightly expanded
How do i open a StreamReader so that i can read an encoded text file, with sharing options so that another process can read the…

Ian Boyd
- 246,734
- 253
- 869
- 1,219
5
votes
3 answers
C#. How come when I use TextReader.Read() it returns an int value? Possible to convert to char?
So TextReader.ReadLine() returns a string, but TextReader.Read() returns an int value. This int value also seems to be in some sort of format that I don't recognize. Is it possible to convert this integer to a character? Thanks for any…

Alexander
- 53
- 1
- 4
5
votes
1 answer
How to string multiple TextReaders together?
I have 3 TextReaders -- a combination of StreamReaders and StringReaders. Conceptually, the concatenation of them is a single text document.
I want to call a method (not under my control) that takes a single TextReader. Is there any built-in or…

Ken
- 396
- 2
- 4
5
votes
2 answers
How can I easily get a TextReader from an XDocument?
Given an XDocument instance, how can I easily get a TextReader that represents that instance?
The best I've been able to come up with is something like this (where xml is an XDocument instance):
var s = new MemoryStream();
var sw = new…

Mark Seemann
- 225,310
- 48
- 427
- 736
4
votes
0 answers
IFilter Textreader not working within IIS/ASP.NET?
I need to extract text from DOC, DOCX and PDF files.
I've downloaded two Windows Forms Application demo projects, one here:
http://www.codeproject.com/Articles/31944/Implementing-a-TextReader-to-extract-various-files
the other…

Cees
- 83
- 6
4
votes
1 answer
C# Memory to TextReader
What is optimal way to get TextReader instance from a Memory object?
I could write something like:
using (var stream = new MemoryStream(body.ToArray()))
using (var reader = new StreamReader(stream))
{
}
but maybe there is a better way?

obratim
- 467
- 5
- 13
4
votes
2 answers
Using TextReader to read bytes
In the past, I have been using a BinaryReader to read a few bytes, but recently, I have gotten this error:
An error has occurred: Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In…

user1914728
- 43
- 1
- 4
3
votes
6 answers
Issues using StreamReader.EndOfStream?
So I'm doing a project where I am reading in a config file. The config file is just a list of string like "D 1 1", "C 2 2", etc. Now I haven't ever done a read/write in C# so I looked it up online expecting to find some sort of rendition of C/C++…

MattMacdonald
- 93
- 1
- 1
- 9
3
votes
2 answers
Java Text Input: How to ignore lines starting with certain characters in them?
I basically want to ignore certain lines with characters in them, like if there's a line
// hello, i'm bill
I want to ignore that line while reading it because it contains the character "//". How can I do that? I tried method skip(), but it gives…

lrvilnius
- 107
- 1
- 3
- 8