Questions tagged [textwriter]

TextWriter is an abstract base within the .NET Framework, and represents a writer that can write a sequential series of characters.

73 questions
1
vote
1 answer

In C#, Why can I use TextWriter in place of StreamWriter?

I'm pretty new to C#, so please excuse any questions which seem basic. I'm wondering why TextWriter and StreamWriter can both serve the same function (or seem to) in my code example (working with an XML serialization method). In this example, I'm…
1
vote
2 answers

Text output file not instantiated

I have two newbie questions. I am attempting to output the data from an array into a text file on vhdl. Despite referencing many online guides to do this, I always come up with a "file does not exist". Any suggestions on what's going…
BayK
  • 37
  • 1
  • 6
1
vote
1 answer

Obtain the current contents of the TextWriter stream

I'm building a custom HtmlHelper for MVC. I'd like to allow the user to add a block of HTML that will be used with the helper. So, I'm planning on having something similar to the following in my view: @using (Html.MyHelper()) { // foo } The…
Jason N. Gaylord
  • 7,910
  • 15
  • 56
  • 95
1
vote
3 answers

How can you use Console.Out to write a byte[] to a file?

In java you can do this: File file = new File(filepath); PrintStream pstream = new PrintStream(new FileOutputStream(file)); System.setOut(pstream); byte[] bytes = GetBytes(); System.out.write(bytes); I want to do something similar in C#. I tried…
John Smith
  • 4,416
  • 7
  • 41
  • 56
1
vote
1 answer

How to Edit .aspx page and Save in asp.net on button click using c#?

I a list of .aspx page which is in DropdownList that are from Application Root Directory. I am showing the Whole .aspx Page content in RichTextBox for Editing. But, When i click on Save Button it shows Error:A potentially dangerous Request.Form…
SHEKHAR SHETE
  • 5,964
  • 15
  • 85
  • 143
1
vote
2 answers

Advanced Chat Program (Writing Prefixes)

I've coded a Chat Program giant and so far have managed to get over every obstacle that has stopped me, even the ones I have thought over for days, but this one I can't get my head around. So I'm working on a prefix system, I type the target name…
Daaksin
  • 834
  • 3
  • 13
  • 28
1
vote
1 answer

Cannot write to a closed TextWriter

I have a error, "Cannot write to a closed TextWriter." Code: public class Logs { static string File_Path= ""; static public FileStream fs; static public StreamWriter sw; public static void Initialize(string path) { …
sezer ural
  • 11
  • 1
  • 2
0
votes
2 answers

The stream is currently in use by a previous operation

I am running to the below issue and unable to workaround it https://andrew.thomas.net.nz/c%23/2020/08/30/Beware-of-using-File-Stream-WriteLineAsync-methods/ I am unable to workaround it since await can't be included inside lock and do not want to…
Mo Haidar
  • 3,748
  • 6
  • 37
  • 76
0
votes
3 answers

How to remove last characters from a string

So I am writing a C# program which combines several text files into one and saves them as a combined text file. One issue I am having, I have a textfield which selects the intended folder the save the compiled reciept, however when selecting the…
0
votes
1 answer

TextWriter: Need to fetch data from DB to excel

I am working on requirement to read data from DB(from an array(String[] getPersons) as input) and write it to excel file. I struck with one scenario where in DB, I am having DepartmentID value as 1,2,3 e.t.c. Where 1 is for CSE,2 for ECE,3 for IT…
tartar
  • 140
  • 8
0
votes
2 answers

Using one memorystream for multiple file search iterations

I'm having several methods which each apply an operation to the a textfile, where the next operation requires the result of the previous operation as input: private TextReader input = new StreamReader("input.txt"); private TextWriter output = new…
0
votes
3 answers

Why does whitespace appear at the end of my C# TextWriter file?

I have created a text file using TextWriter C#, on final creation the text file often has various rows of whitespace at the end of the file. The whitespace is not included in any of the string objects that make up the file and I don’t know what is…
Steven
  • 177
  • 1
  • 10
0
votes
1 answer

Custom textwriter for Console outputstream not working in external classes

I'm trying to forward the Console output to a Windows Forms TextBox control. So I attached a custom TextWriter to the Console which appends the output to the TextBox. But I think the TextWriter or TextBox is inaccessible from within an external…
Bob Vandevliet
  • 213
  • 3
  • 14
0
votes
0 answers

Out of Memory using TextWriter Stream with HttpWebRequest

Thanks for your great suggestions to an OOM (out of memory) problem I'm seeing in code intended to stream files for web services. [I hope it is OK to start another thread which provides a bit more detail.] From the suggestions, I shrunk the buffer…
George
  • 211
  • 5
  • 12
0
votes
1 answer

Is flushing automatic in TextWriter Synchronized?

I checked this code in debug. The file exists when it's executing, and string contents has some text. TextWriter.Synchronized(new StreamWriter(tmpOutput)).WriteLine(contents) Yet the file is empty after this line is executing. Is Flush…
Jeanne Lane
  • 495
  • 1
  • 9
  • 26