textreader

In C#, how can I create a TextReader object from a string (without writing to disk)

孤者浪人 提交于 2019-11-29 04:18:18
问题 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 code- In the original sample, a new StreamReader is looking for a file called "data.csv". I'm hoping to supply it via TextBox_StartData.Text. Using this code below doesn't compile. TextReader sr = new StringReader(TextBox_StartData.Text); using

How to string multiple TextReaders together?

≡放荡痞女 提交于 2019-11-28 08:39:16
问题 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 own TextReader subclass, but it looks like a fair amount of work. In that case, I'd just write them all out to a temp file and then open it with a single

Sharing violation IOException while reading and writing to file C#

此生再无相见时 提交于 2019-11-27 05:33:59
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){ fileNo = int.Parse(line); twLog = new StreamWriter("log_" + line + ".txt"); }else{ twLog = new StreamWriter("log_" + fileNo.toString() + ".txt"); } System.IO.File.WriteAllText("file_no.txt",string.Empty); tw.WriteLine((fileNo++).ToString()); tr.Close(); tw.Close(); twLog.Close(); It throws this error: IOException: Sharing violation on path C:\Users

Sharing violation IOException while reading and writing to file C#

Deadly 提交于 2019-11-26 11:39:09
问题 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){ fileNo = int.Parse(line); twLog = new StreamWriter(\"log_\" + line + \".txt\"); }else{ twLog = new StreamWriter(\"log_\" + fileNo.toString() + \".txt\"); } System.IO.File.WriteAllText(\"file_no.txt\",string.Empty); tw.WriteLine((fileNo++).ToString