Questions tagged [streamwriter]

StreamWriter is designed for character output in a particular encoding, whereas classes derived from Stream are designed for byte input and output.

In .Net StreamWriter (under System.IO) is designed for character output in a particular encoding, whereas classes derived from Stream are designed for byte input and output.

StreamWriter defaults to using an instance of UTF8Encoding unless specified otherwise. This instance of UTF8Encoding is constructed without a byte order mark (BOM), so its GetPreamble method returns an empty byte array. The default UTF-8 encoding for this constructor throws an exception on invalid bytes. This behavior is different from the behavior provided by the encoding object in the Encoding.UTF8 property. To specify a BOM and determine whether an exception is thrown on invalid bytes, use a constructor that accepts an encoding object as a parameter, such as StreamWriter(String, Boolean, Encoding) or StreamWriter.

By default, a StreamWriter is not thread safe
See official documentation from Microsoft.

1524 questions
-1
votes
3 answers

Writing List contents to text file after deleting string

I'm trying to get the contents of a Text File, delete a line of string, and re-write back to the Text File, deleting the line of string. I'm using StreamReader to get the text, importing into a List, removing the string, then rewriting using…
Van Man
  • 51
  • 1
  • 9
-1
votes
2 answers

VB.NET write to file

This should be an easy one, but I'm strugling. I've developed a web page and I'm trying to load values into a text file. I have the asp webform with a textbox and a button. When the button is pressed loads the message from the textbox to the text…
Selrac
  • 2,203
  • 9
  • 41
  • 84
-1
votes
1 answer

How to prevent overwriting in a text file?

I have a trouble with the following code. It should prevent overwriting records in the text file. My code is like that: public static void WritingMethod() { StreamWriter Sw = new StreamWriter("fileone.txt", true); string output =…
Mina Hafzalla
  • 2,681
  • 9
  • 30
  • 44
-1
votes
1 answer

Visual studio bug with StreamWriter or my misunderstanding?

I have to work with some files containing Cyrillic text and I am using StreamReader/StreamWriter in Visual Studio 2012 Ultimate. However, there is some ridiculous problem (or my misunderstanding). The following constructor works just fine: using…
John Smith
  • 23
  • 2
  • 5
-1
votes
1 answer

Follow up Writing information from combo box to text file

with reference to this help topic Writing information from Combo-box to text file i cannot figure out how to get it to not add a space after each entry eg John Mary Joe instead of John_ Mary_ Joe_ How do I get it just write the entry code in…
-1
votes
3 answers

problems with appending text to text file?

i am trying to write a code where the user enters delivery details into text box and the text gets added to a txt file (notepad txt file). This is my attempt, i get an extra line with " , ," why does it not add the text from textbox to the text…
-1
votes
1 answer

how to close StreamWriter object

I have one problem in my application. I need to create two CSV files from the two SQL query results. I created that one. I'm using StreamWriter to write the data into the CSV files. My problem is first query result also written into the second…
Stefan Edwards
  • 87
  • 1
  • 5
  • 13
-1
votes
1 answer

c# StreamWriter uses 50% cpu

I've tried everything that I can think of and I'm about ready to pull my hair out. I have an application that communicates with a modem using a TCPClient, NetworkStream, StreamWriter and StreamReader. The modem will only accept one connection…
DWCP
  • 136
  • 1
  • 4
-1
votes
1 answer

StreamWriter failing to run after 1st iteration in for loop

I'm having issues using StreamWriter to code a scraper for a current project i've got. The loop i've coded is below I've debugged all the variables coming into the loop and everything is set as it should be. When i pass in a url and the range to…
BarryH1987
  • 65
  • 12
-1
votes
3 answers

StreamWriter overwriting previous records?

Hi I am wondering how I can keep the previous records with my stream writer, if I use the below code it works fine when the student record is created but when I create a second student record the previous record is gone? How can I keep all records? …
G Gr
  • 6,030
  • 20
  • 91
  • 184
-2
votes
2 answers

StreamWriter crashes with large text files in C#

I am using StreamWriter to write to a file. When I use a text with 10-50 word text, it works properly. However when i call the function again (it exceeds the 50 words) it crashes. Why is this happening? Any suggestions? Here is the…
LuckySlevin
  • 695
  • 3
  • 16
  • 23
-2
votes
1 answer

My json string is too long for the StreamWriter object

I'm trying to serialize a json string into an object. I'm forced to use .net version 4.6.2 so I can't use the tools I would normally use. I can't either user async because of the framework I'm working in. I have come up with this method and it's…
Kresten
  • 810
  • 13
  • 36
-2
votes
1 answer

how do I make a text file line into a list

is it possible to make this into a list and then make a code where I can delete what's inside the list per line (text file) and then searching the contents of the list class data { public void addData(string user_name, string user_email,…
-2
votes
1 answer

Save to file broken - C#

I try to use a txt file as a backup: when a checkbox is activated, we add 1 in a "victory" txt file and when it is deactivated we add 1 in a "loose" txt file, and here is my problem: For example if the checkbox is disabled, I run the script and I…
Pekmi
  • 21
  • 3
-2
votes
1 answer

C# WPF Application don't write a file after publishing

First of all, the forum has given me very good ideas and solutions just by reading along. To my current case I willnot really looking for it. I have written a WPF application that works perfectly in debug and release mode. However, as soon as I…
Trat
  • 1