streamreader

OpenFileDialog reads only the first file

被刻印的时光 ゝ 提交于 2019-12-12 01:51:37
问题 I'm using the following code to open multiple XML files and read the contents of the files but it doesn't work. OpenFD.Filter = "XML Files (*.xml)|*.xml"; OpenFD.Multiselect = true; if (OpenFD.ShowDialog() == DialogResult.OK) { foreach (string file in OpenFD.FileNames) { MessageBox.Show(file); System.IO.Stream fileStream = OpenFD.OpenFile(); System.IO.StreamReader streamReader = new System.IO.StreamReader(fileStream); using (streamReader) { MessageBox.Show(streamReader.ReadToEnd()); }

Comparing and combining arrays of strings from text files

岁酱吖の 提交于 2019-12-12 01:37:16
问题 Right off the bat I dont think the wording of the question is accurate, I just dont really know what to write. That being said, I have 3 txt files that I am loading into this program, Dudes, Tunes, and Bands. Dudes is formatted like this name|instrument, Tunes like this; songName|composer|band|coverArtists1|coverArtists2|etc. And band like this; bandName|bandType|member1|member2|etc. The "|" is where I split the data so each line of the text files become arrays of strings. What I am trying to

Null reference exception while iterating over a list of StreamReader objects

守給你的承諾、 提交于 2019-12-11 20:29:29
问题 I am making a simple Program which searches for a particular Name in a set of files.I have around 23 files to go through. To achieve this I am using StreamReader class, therefore, to write less of code, I have made a List<StreamReader> FileList = new List<StreamReader>(); list containing elements of type StreamReader and my plan is to iterate over the list and open each file: foreach(StreamReader Element in FileList) { while (!Element.EndOfStream) { // Code to process the file here. } } I

error: The stream does not support concurrent IO read or write operations

喜夏-厌秋 提交于 2019-12-11 18:42:39
问题 I am trying to log in to a website from my C# web application to send emails directly from the application instead of making user visit the website personally. NOTE: The website, I am trying to log into changes the id of the textboxes everytime the page is loaded, EVEN DURING THE SAME SESSION. Therefore I decided to read the page source, extract the id of the textbox and then use that id while posting the message. public partial class sender : System.Web.UI.Page { string userID, userPwd,

How to read multilines from text file in c#

家住魔仙堡 提交于 2019-12-11 16:44:08
问题 I have a text file which contains user records.In the text file one user record is present in three lines of text file.Now as per my requirement i have to read first three lines for one User, Process it and insert into database and next three lines for second user and so on.. Here is the code that i have used for single line reading from text files.. if (System.IO.File.Exists(location) == true) { using (StreamReader reader = new StreamReader(location)) { while ((line = reader.ReadLine()) !=

Can't get the proper Index to return

↘锁芯ラ 提交于 2019-12-11 13:48:12
问题 Alright, so firstly I want to thank everyone for helping me so much in the last couple weeks, here's another one!!! I have a file and I'm using Regex to find how many times the term "TamedName" comes up. That's the easy part :) Originally, I was setting it up like this StreamReader ff = new StreamReader(fileName); String D = ff.ReadToEnd(); Regex rx = new Regex("TamedName"); foreach (Match Dino in rx.Matches(D)) { if (richTextBox2.Text == "") richTextBox2.Text += string.Format("{0} - {1:X} -

C# Read from text file separated by commas into 2d array

妖精的绣舞 提交于 2019-12-11 12:55:25
问题 I currently have this: using (StreamReader sr = new StreamReader("answers.txt")) { for (iCountLine = 0; iCountLine < 10; iCountLine++) { for (iCountAnswer = 0; iCountAnswer < 4; iCountAnswer++) { sQuestionAnswers[iCountLine, iCountAnswer] = } } } My text file is formatted like this (10 lines of text, with 4 items on each line separated by commas): example, example, example, example 123, 123, 123, 123 I'm not sure what I need after the "=" in the for loop to get it to read and split the

how to read items from file into a list of items and set the properties to the value in the file?

懵懂的女人 提交于 2019-12-11 10:17:47
问题 Hello I am trying to create a stock log system in c# winforms and i am a bit stuck for ideas on how to read the items back into a list and storing the data into the properties. I will be reading in from a csv file where each line is 1 item and each property is separated by a comma. the main Class using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; //using System

C# Convert Unicode chars [duplicate]

北战南征 提交于 2019-12-11 09:21:37
问题 This question already has answers here : Unicode characters string (3 answers) Closed 3 years ago . is it possible to convert a string like "\u00e8" (Got it by reading a WebRequestResponse with Streamreader) to it's unicode char(è)? Tried many things with Encoding, but nothing works. 回答1: You can use Regex.Unescape(), which unescapes any escape sequences that are valid for a Regex (including \uXXXX ). Note that it also unescapes other sequences like \t , \n , and \[ . 来源: https:/

check for null and end of stream in same statement

和自甴很熟 提交于 2019-12-11 09:15:56
问题 while ((line = sr.ReadLine()) != null && !sr.EndOfStream) This does not work. It literally keeps looping and I get an exception because "line" is null, and the EndofStream has been reached. Any idea? 回答1: If you put both checking together, code will escape looping even if ReadLine() is null before reaching EndOfStream . Following is a breakdown version but will go through the whole stream. while (!sr.EndOfStream) { if ((line = sr.ReadLine()) != null) { //do your work here } } 回答2: You can