FAQ Database Discussion Community


C# StreamReader Load Data and post to Form

c#,streamreader,streamwriter
I've been struggling to figure out exactly the best way to handle my situation for a few days now. I'm not able to get the program to function the way I desire. What I have is a .txt file, that has two columns, and 11 seperate lines. It looks as...

Reading integers from a text file only and seperating

vb.net,listbox,integer,streamreader
I have created a program that successfully reads integers only from a text file that contains string as well into a listbox. For example: The text file contains: Tyler 7 Daniel 2 Mike 6 Rory 9 The listbox will then show: 7269. However I plan to sort these numbers from...

C#, Split after 2 ;'s in same line

c#,visual-studio-2010,csv,streamreader,streamwriter
I'm generating a list of from/to coordinate points, together with the distance/time between those points. For illustration: the header of the end product looks like this writer.WriteLine("fromX" + ";" + "fromY" + ";" + "toX" + ";" + "toY" + ";" + "distance" + ";" + "time"); The process of...

Reading files in c# with filestream and streamreader

c#,byte,filestream,streamreader,readline
I have a file, which contains data, I want to read it as byte[] and divide into 3 blocks. First line might be read as string, then 2nd block, might be 1-3 length of lines and all left bytes as block 3. I was wondering, how can I get that...

How to check if a textbox has a line from a TXT File with C#

c#,textbox,.net-4.5,streamreader
It's simple what I'm trying to do; when I click a button, my app should check if textBox1.Text has a line from a text file. Note: I don't want to check if textbox has all the text file in it, just to see if it has a LINE from it....

Joining two files in C#, split options

c#,file,split,stream,streamreader
I am currently trying to work on files, joining multiple of them and having problem because the last work from file 1 is linked with first word from file 2. For example: File 1:John has got new haircut File 2: Mike has got new haircut and it prints me "haircutMike"....

StreamReader row and line delimiters

c#,arrays,tokenize,delimiter,streamreader
I am trying to figure out how to tokenize a StreamReader of a text file. I have been able to separate the lines, but now I am trying to figure out how to break down those lines by a tab delimiter as well. This is what I have so far....

Search for a string in text file, if found, read the next line [closed]

c#,streamreader
I'm new to C# obviously. I'm looking for a way to read each line in a text file and search for a unique string in that text file. If if finds the string, then I need it to read the next line only and output it to a textbox. Any...

Delete, copy, and paste string in an array in a text file to a new arry in a text file

c#,arrays,streamreader,streamwriter,file.readalllines
I need some help with file streaming. I have a program that will record names into a string array that will be written to a .txt file. Then if a user wants to delete a specific string from the array in the .txt file. the program will search for the...

How to wrap a streamreader with the using directive?

c#,asp.net,streamreader,using
I have this code that works on one Windows Server 2008 R2 but not a fresh new server 2008 R2 install. The code below is locking some text files on the new server but not the old one which is very strange. I'm very sure it is this code because...

Iterating multiple txt files in folder to read them in C#

c#,file,stream,iteration,streamreader
Problem: I need to iterate through multiple files in a folder and read them. They are .txt files. While reading I need to note what words occured in each file. For example: File 1 text: "John is my friend friend" -> words: John, is, my, friend File 2 text: "John...

Split text file into several parts by character

vb.net,winforms,text-files,streamreader
I apologise in advance if there is already an answer to this problem; if so please just link it (I have looked, btw! I just didn't find anything relating to my specific example) :) I have a text (.txt) file which contains data in the form 1.10.100.0.200 where 1, 10,...

Reading textfile skipping bunch of lines then proceeding to other lines

c#,linq,streamreader
I want to skip lines that i will read in the text file, as you can see below the line 0, line 1 and line 2 is skip (first three lines of text file) then it follows a read this (3 read this) then next is (4 skip this) this...

Read only certain columns from a text file

c#,winforms,streamreader
I need to read from a text file and only get certain data from it. The text file has multiple lines, similar to below 12/05/2014 06:52 c:\BACKUPS\INT100\BACKUP\BACKUP.ZIP 12/05/2014 06:51 c:\BACKUPS\INT1000\BACKUP\BACKUP.ZIP I need the date, time and the number (in this case 100 and 1000), but can't figure out how to...

StreamReader not finding end of file

vb.net,streamreader
I simply need to read lines from a text file and show them. When I run this I can see that id does what I want, but after it reads the last value it just shows a blank form on my screen and does not move on. It seems like...

Any way to force read next line while in StreamReader loop?

vb.net,while-loop,streamreader
I'm working on a txt file and I was wondering if there was a way to force the streamreader to read the next line after I've used the value of the one it currently read. My code: Private Sub subTest() Dim sr As New StreamReader("d:\input\cleanedUp.txt") Dim doc As New XmlDocument...

Read multiple lines from textfile into array

c#,arrays,loops,streamreader
I'm working on a small program which holds information about people. The information is stored in a textfile as a sentence and the words are separated by ";". I know how to read the lines with a streamreader, I do this upon clicking on a button. I then split the...

Very slow StreamReader for medium sized files.

c#,optimization,character-encoding,streamreader
I am reading text files into program(they are code in Unicode, the output must be in utf-8). The code below works fine for smaller ones (around 150 lines, where line is one word only), however when I am using it on bigger files(like 20.000 line, still only one word on...

Loading cell values in dataGridView from text file C#

c#,datagridview,streamreader,streamwriter
I am using a StreamWriter to write all values on all exisiting cells in a dataGridView, that writer is working perfect. But my reader isn't doing its work very good. This is my writer code(which has no problem): StreamWriter writer = new StreamWriter(valuePath); foreach (DataGridViewRow row in dataGridView1.Rows) { foreach...

streamreader's basestream position using mono

c#,linux,mono,streamreader
I am trying to write some simple code to index some wikipedia xml pages. The idea was to get the byte offset of each character by reading in a character using streamreader, then saving the position from the byte stream so I could get back to that position later. using...

Overwriting lines in a txt file while searching for the lines

c#,streamreader,streamwriter
I'm working on a video game with C#. I have a list of users with their coin amounts in a .txt file, and I want for their amounts to be overwritten when they save. I can't figure out how to use SteamWriter within SteamReader without a "file already being used"...

C# Reading a file add special characters

c#,split,streamreader
I am reading a text file with this structure: 20150218;"C7";"B895";00101;"FTBCCAL16" I read the line and split like this: System.IO.StreamReader fichero = new System.IO.StreamReader(ruta, Encoding.Default); while ((linea = fichero.ReadLine()) != null) { // Split by ";" String[] separador = linea.Split(';'); } But when I see the content of "linea", I have...

Can I put StreamReaders in a list? Or any other way to read a lot of text files at once?

c#,list,text,streamreader
I have a lot of text files and want to read them all by once, how do I do this? This is my code till now: List<StreamReader> lijst = new List<StreamReader>(); using (StreamReader qwe = new StreamReader("C:\\123.txt")) using (StreamReader qwer = new StreamReader("C:\\1234.txt")) lijst.Add(qwe); lijst.Add(qwer); But I get an ObjectDisposedException(Cannot...

Open/save multiple textbox values c# windows forms

c#,winforms,streamreader,openfiledialog
I created simple example and I can't find solution anywhere. I want to save UI textbox data, and open it in another(same) windows form file. Here is code example: private void btnSave_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); if (sfd.ShowDialog() == DialogResult.OK) { StreamWriter write = new...

C# - StreamReader.ReadToEnd() is extremely slow

.net,performance,stream,streamreader,httpwebresponse
I'm making a Web Crawler and I just found out that one of my methods, GetHTML, is very slow because it uses a StreamReader to get a string of the HTML out of the HttpWebResponse object. Here is the method: static string GetHTML(string URL) { HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL); Request.Proxy...

Easiest way to Add lines wrong a .txt file to a list

c#,string,list,streamreader
At the moment I am opening the .txt file twice, once to get the number of all the lines, second to add a line to a list as much as how much lines there are in the .txt file. Is there an easier/better way to do this? This is my...

Asynchronously manipulating data from streamReader in F#

asynchronous,f#,streamreader
On the line of Read large txt file multithreaded?, I have the doubt of whether it is equivalent to pass to each thread an sliced chunk of a Seq and whether it will safely handle the paralellism; is it StreamReader thread-safe? Here is the code I am using to test...

Lambda into a method

c#,lambda,streamreader
I have a method where I'm reading a textfile. I have to get the words in the textfile which start with "ART". I have a foreach loop which loops through the method. class ProductsList { public static void Main() { String path = @"D:\ProductsProjects\products.txt"; GetProducts(path, s => s.StartsWith("ART")); //foreach (String...

how to draw captcha image from other web site

c#,asp.net,.net,streamreader
i have one important project. i have to draw dynamically captcha image from running other web site captcha. here i have to made one web request to other login page. and draw captcha same as displayed other web site. here i have to set this captcha image src to my...

Streamreader Readline() throws exception

c#,sockets,streamreader
I have a client which talks to a server, the code below is supposed to print on the console what was typed in - this spans over multiple lines. The problem is that it displays all the lines, then throws an exception. I have tried different ways in order to...