streamreader

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 easy way to make a concatenating TextReader from multiple TextReaders? (I could write my o...

Reverse Streamreader

I have an application that I've been tasked with cleaning up after. The application itself is relatively simple - it runs a SQL query, consumes a web service, and spews the results to a log file. My job is to archive the files to our NAS after the application is done with them. It locks the files exclusively until it's done with them so ...

Problem pulling data from website in .NET and C#

I have written a web scraping program to go to a list of pages and write all the html to a file. The problem is that when I pull a block of text some of the characters get written as '�'. How do I pull those characters into my text file? Here is my code: string baseUri = String.Format("http://www.rogersmushrooms.com/gallery/loadimage...

StreamReader.EndOfStream produces IOException

I'm working on an application that accepts TCP connections and reads in data until an </File> marker is read and then writes that data to the filesystem. I don't want to disconnect, I want to let the client sending the data to do that so they can send multiple files in one connection. I'm using the StreamReader.EndOfStream around my out...

C# StreamWriter and StreamReader memory managment problem, why won't memory used deallocate?

So I'm using a StreamReader that uses a MemoryStream to write to a StreamWriter and inside of this application but the memory usage increases by 300mb (From one of the larger inputs) and does not deallocate after Im done using it: StreamWriter log = new StreamWriter("tempFile.txt"); log.Write(reader.ReadToEnd()); log.Close(); reader.Di...

is there a way to remove the first line from a StreamReader

i have a streamreader which loads up a csvfile, the issue is that there is one extra row at the top of the data that i want to ignore. I am using the CSVReader project which is great but csv.GetFieldHeaders(); always looks at the first row. Instead of going into the CSVReader source code and changing it, i thought it might be easi...

StreamReader and buffer in C#

I've a question about buffer usage with StreamReader. Here: http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx you can see: "When reading from a Stream, it is more efficient to use a buffer that is the same size as the internal buffer of the stream.". According to this weblog , the internal buffer size of a Stream...

Combine a serialized object with an existing xml doc and return it?

Hello, I'm trying to figure out to to combine a serialized object with an existing xml doc and return it as a webservice. Thanks ahead for you help. Sample code: [WebMethod] public string GetApple() { Apples apples = Report.GetReport(); // this returns: // <Apples xmlns:xsi="http://www.w3.org/2001/XMLSchema-...

How do I load a file that I bundled with the install of my C# program?

I need to do something like this: StreamReader reader = new System.IO.StreamReader(@"C:\Program Files\The Awesome Program That I Made\awesomeloadablefile.ldf"); Except I don't know where the user has installed the program. How is my program supposed to know where the installed files are? I am a noob, in case you hadn't noticed....

c# stop a streamreader after a few seconds. Is this possible?

I have web request and i read information with streamreader. I want to stop after this streamreader after 15 seconds later. Because sometimes reading process takes more time but sometimes it goes well. If reading process takes time more then 15 seconds how can i stop it? I am open all ideas. ...

Browse a file from my pc using web application in asp.net

Hi, I have a web application which I uploaded using IIS. I want the users using the application would be able to select a file located on their (the user) computer and read its contents. The code is: TextReader trs = new StreamReader(faFile.Value); DataAccessLayer.clearFA(); string line = trs.ReadLine(); ...

StreamReader ReadBlock hangs on binary files

I've got a little class that accepts a POST from a browser that contains file uploads. I'm using a StreamReader to read it in. I read the header, then when I get to the body, I get the content length and make an array of that size and then stream.ReadBlock() on that: char[] buffer = new char[contentLength]; stream.ReadBlock(buffer, 0, ...

Do I need to Dispose XmlReader if I Dispose its underlying Stream?

I have the following method GetData that creates a StreamReader from a file. private void GetData(string file) { string filename = Path.GetFileNameWithoutExtension(file); XmlDocument xmldoc = new XmlDocument(); using (StreamReader sr = new StreamReader(file)) { Stream bs = sr.BaseStream; Stream cl = main...

Is there a faster way to read from a file and insert into SQLite.

Afternoon everyone. I'm not that familiar with SQLite so I haven't messed with all of the settings of the database. I'm rather familiar with SQL Server, Oracle and even some Access and mySQL. Well, currently, I'm taking a file with 110,000+ records and reading the file line by line, parsing the data and running an insert statement to ...

Search line in *.CSV-

I can't belive, the easiest task won't work! I just want to loop through a csv file by using the StreamReader-Class and find a key in a associative line. e.g.: key1;value1 key2;value2 key3;value3 If the key exists, no problems. Otherwise EOF should be reached, but it does not work! If I discard the buffered data, EOF will be reach...

Read from StreamReader in batches (C#)

Hello, I have been running into OutOfMemory Exceptions while trying to load an 800MB text file into a DataTable via StreamReader. I was wondering if there a way to load the DataTable from the memory stream in batches, ie, read the first 10,000 rows of the text file from StreamReader, create DataTable, do something with DataTable, then ...

simultaneous read-write a file in C#

I have a file containing data that I'd like to monitor changes to, as well as add changes of my own. Think like "Tail -f foo.txt". Based on this thread, it looks like I should just create a filestream, and pass it both to a writer and reader. However, when the reader reaches the end of the original file, it fails to see updates I wr...

Closing Stream Read and Stream Writer when the form exits

Hey guys, having a bit of trouble here. So I have a load button that loads the file, and a save button the saves the file. I also have a exit button that closes the program. What I need help with is when I close the program, I wont to check whether there are any StreamReader or StreamWriter things that have not been closed. Heres what ...

Why disposing StreamReader makes a stream unreadable?

Hi, I need to read a stream two times, from start to end. But the following code throws an ObjectDisposedException: Cannot access a closed file exception. string fileToReadPath = @"<path here>"; using (FileStream fs = new FileStream(fileToReadPath, FileMode.Open)) { using (StreamReader reader = new StreamReader(fs)) { ...

Exclusive access to text file, to read and overwrite it.

Hi, I'd like to open a text file and not allow any other processes to write to it. I understand I can do this with the following FileStream: Dim fs As New FileStream(_FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read) Once I have access like this I need to read all of the lines (I will use a StreamReader(fs)) and then I w...