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.
1,524
questions
0
votes
1
answer
50
views
C# Export Logs to 2 txt files
So I have a button made from my xaml file (view), called Export.
When the user clicks on it, the logs created during the run of the app get exported to Logs.txt.
If there are Warnings, Errors or ...
0
votes
0
answers
29
views
Does a MailMessage Attached to a Stream Generate a File?
In one method I have the below code:
var newMessage = new MailMessage();
newMessage.Attachments.Add(new Attachment(ToStream("testAttachment"), MediaTypeNames.Text.Plain));
Then I have this ...
1
vote
1
answer
30
views
How to ignore commas in cell value when using StreamWriter to write to csv output
I am processing a .txt file, which needs to be repeated every 10 lines. I then want to turn this into a .csv file. However, some of the .txt file contains commas which I want to keep in a single cell ...
0
votes
0
answers
43
views
Does WriteAllLines delete the existing file and recreate it, or overwrite the data inside it?
I use the File.WriteAllLines() method in my project. The txt file is to be synced to a remote server (via another application, Autodesk Docs in my case) upon Save action.
I am not sure why, but using ...
3
votes
2
answers
108
views
C# StreamReader throws OutOfMemoryException on last line when splitting large delimited text file
I am writing a function in C# to split a large delimited file into smaller delimited files. I am writing this function because a 2.7 GB file was taking hours to ETL and was causing a bottleneck to ...
1
vote
1
answer
65
views
C# Unable to overwrite file contents when file extension is .txt
I am attempting to write a string to a file that the user specifies using the SaveFileDialog component.
The output file is created and populated successfully if it does not already exist.
However, if ...
0
votes
1
answer
21
views
StreamWriter.Write that returned by a method not working
I have a program file in C# that in some point looks like this:
var lowest3Students = studentAVGsOrdered.Take(3);
using var writer4 = GetStreamWriter(folder, "file4.txt");
WriteStudents(...
0
votes
1
answer
93
views
C# System.IO : The process cannot access the file path because it is being used by another process
I am trying to debug the code for uploading the .xlsx file through my application in my local system. At the time of appending log data to the log file this exception
The process cannot access the ...
0
votes
1
answer
38
views
process cannot access the file while trying to use StreamWriter [duplicate]
The process cannot access the file 'C:\csharp\notebook.txt' because it
is being used by another process.
How is it used by another process, if I haven't used StreamWriter yet? I want to add new text ...
-1
votes
2
answers
69
views
How do I open with read-only mode while saving csv file?
In C#, my program creates *.csv file.
And append data to this file every 1ms.
While append data, when I open *.csv file, this error occurs
I JUST want to open "ONLY READ MODE" while append ...
1
vote
1
answer
47
views
Text file is locked for openning when running the script but I can open it manually
I have the following PowerShell script:
do{
$Error[0]= $null
$StreamWrite = [System.IO.StreamWriter]::new($PathToTextFile,$true,[system.Text.Encoding]::Unicode)
}while ($Error[0] -ne $...
0
votes
0
answers
142
views
How to close the tcp connection fully when using asyncio open_connection() when connected to server?
In the following code, the client opens connection to server using asyncio.open_connection():
self.client_reader, self.client_writer = await asyncio.open_connection(
self.host,
...
1
vote
2
answers
39
views
SerializeObject & StreamWriter created file not complete
here is my code :
string json = JsonConvert.SerializeObject(stocksArticles,Formatting.Indented);
StreamWriter sw = new StreamWriter("Export\\Stocks.json");
sw.Write(json);
it's working fine ...
0
votes
1
answer
64
views
using Steamwriter to write to a file gets stuck in foreach loop
I'm trying to create a small program that takes a html file as an input, and writes all links into a new output file. My problem is that the output file is empty. When debugging, it looks like I get ...
1
vote
1
answer
64
views
"WriteLine" stop writing a file. (Windows PowerShell)
I am trying to create a script for the university, that sorts the number of processes in the system by their handles number and saves them in a file. So far so good, sounds easy. But when I thought I ...
0
votes
0
answers
25
views
"Cannot access file path" when writing data to text using StreamWriter in C#/.net [duplicate]
I have created an app in which I read a sensor and write the sensor data to text. My code for writing to the text file is:
private int outputData
{
set
{
if (...
0
votes
1
answer
45
views
How to access a relative URI using StreamReader in C#
So I'm trying to read/write to a generic .dat file which contains plain text. I've been trying to do it with StreamReader/Writer as this seemed to be the neatest way of doing things.
The data.dat file ...
-1
votes
1
answer
83
views
How to edit specific line in a textfile?
I know, that i can use ReadAllLines method and edit line using it's index. But this way not good for huge files. For example, i have file with 800,000 lines, and i need to find a line, which contains &...
3
votes
2
answers
269
views
In C#, using "using" results in errors, is there a better practice than just not using "using"?
I have the following method:
[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "If we dispose of the csvWriter, it won't be ...
-1
votes
1
answer
130
views
StreamWriter fails to create a text file inside a folder with added DateTime.Now [duplicate]
I wanted to add a timestamp to the writing file and tried this:
TextWriter iterationLogger = new StreamWriter($"{DateTime.Now} Iteration log.txt");
Then StremWritter throws exception The ...
0
votes
0
answers
16
views
create an tempDir and save it into an IFile with the external_drive_lib
Currently i am Getting from the IDrive an folder which has a file and i am copying this file into a tempfile which i am reading with the Streamreader, but is there a way to create this IFIle or i ...
-3
votes
1
answer
658
views
C# "The process cannot access the file because it is being used by another process" error
I've been trying to figure out what's my error here for a few minutes now. can someone help?
public void UpdateItemList(string word, string replacement)
{
StreamReader ...
1
vote
1
answer
129
views
Do I need to dispose of StreamWriter when generating a stream from a string?
So I have the following code to convert a string to a MemoryStream https://stackoverflow.com/a/1879470/2987066
public static Stream GenerateStreamFromString(string s)
{
var stream = new ...
0
votes
1
answer
73
views
Within a File StreamWriter scope how to get the Total lines counts in a file
How to do get the Total lines of the file when we are within in a StreamWriter scope.
Based on the total number of lines count I am writing some more lines at the end of the file.
I have tried the ...
-1
votes
1
answer
40
views
no duplication of username does not work on my C# windows form, it only debugs the first array of my .txt file
Example .txt file output will be:
lastname|firstname|tintin|password|Manager
lastname|firstname|carley|password|Manager
If I try to register username 'tintin' and other data, it debugs it and says ...
0
votes
1
answer
94
views
Using Stax2 to escape special characters in Scala
I am trying to use stax2 in order to write xml files with escaping special characters for the attributes.
When I am trying to achieve is an exact output like this:
<elem1 att1="This 
 ...
0
votes
0
answers
39
views
How to detect and print the encoding of a list of .sql files in a particular directory?
I have a list of .sql files that need to checked for their encoding before i make changes to them. They are either in utf 8 or utf 16. How can I make some changes to my code so that it enter code ...
2
votes
2
answers
191
views
My windows service in C# cannot write to file, when at the same time another C# app is trying to read the file
I have a Windows service in C# that is writing some data to a text file every 35ms. Normally everything was working fine. But recently I have programmed a simple windows forms app that is reading data ...
-1
votes
1
answer
70
views
Declaring new TextWriter with StreamWriter causes "System.IO.IOException: 'The process cannot access the file"
I have the file being used by another process. However I need to be able to save to it using TextWriter (C# .NET). What can I do to get around this?
("The Process cannot access the File error&...
1
vote
1
answer
125
views
How do I overwrite a text file line by line using StreamWriter WriteLine in c#
As part of my c# learning, I have a simple game on a console application. I have now added a text file to record the top score. It has 4 lines, date, number of attempts, time in minutes and additional ...
0
votes
1
answer
73
views
How to create multiple Files regarding to an object-attribute
A method receives an object list each entity has the following attributes:
name
room
The list contains, for example, the following objects:
name: pc01 room: a1
name: pc02 room: a1
name: pc01 room: ...
0
votes
0
answers
40
views
Should i close each substreams of filestream or closing filestream will be enought?
I readed a lot of topics about C# streams, but did not find my situation.
For learing purpose i did list-file json-bd like:
public sealed class JSONBD<T> : IDisposable {
private FileStream ...
1
vote
1
answer
43
views
How to store specific lines in a text file in a array (i.e 2 seperate bank accounts)
I am doing a ATM project for my computer science class and we are required to make an ATM that stores and reads accounts in a text file. I am stuck trying to figure out how I can get an array in the ...
0
votes
3
answers
85
views
How to overwrite a string in a text document
Doing a ATM Machine for my computer science project and I wanted to know how to overwrite a specific string of text in a text document.
Ex: The program asks the user how much they want to deposit; ...
0
votes
3
answers
217
views
C# MemoryStream csv file not writing
I'm writing something that will create a .csv file in memory and email it as an attachment. The code below successfully emails a .csv file, but it is empty. I'm sure I'm missing something simple...
...
0
votes
0
answers
20
views
XStream - data within a tag should be indented identically
I could use some help to get a better XML output. I hope to find a solution here! Couldn't find any solution for this.
That is my current output:
<java.util.Arrays_-ArrayList>
<a class=&...
1
vote
0
answers
34
views
Running cmd in a single textbox: how to put the cursor in the right place
I would like to run cmd.exe in one single textbox. When I use the code down below, everything works fine. The only thing is that the cursor is located below the prompt line, so:
C:\Users\myuser\...
-2
votes
1
answer
191
views
My json string is too long for the StreamWriter object [closed]
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 ...
1
vote
0
answers
40
views
Keeping multiple StreamWriters open or constatly open a new one?
So I have this application that needs to write to 12 different files 10 times a second a few thousand characters strings via different Tasks, figure something like this:
public static void Main()
{...
0
votes
0
answers
22
views
Preserving basic application functions when using StandardInput/Output redirection
I’m trying to run an external (non-GUI) application and use RedirectStandardInput and RedirectStandardOutput to send data to and receive data from this application to a TextBox. The main problem is ...
0
votes
0
answers
72
views
stop streamwriter writer and convert to string
i want to pull git log with cmd panel. this is relatively easy to do with
Process process = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "cmd.exe";
info....
0
votes
2
answers
409
views
Is it correct to leverage a stream writer WriteLineAsync with WhenAll
I have a snippet of code that is writing to a memory stream in an asynchronous way (.NET Standard 2.1)
Create a list of hot tasks, one per a line
Then await when all of them will be finished
Flush ...
-2
votes
1
answer
37
views
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 ...
0
votes
0
answers
231
views
Asyncio stream writer persists data
I'm using asyncio to create a websocket between my clients and server.
I am using StreamWriter.write() to send data to and from the client.
data = {
"type": "DRAW_RECT",...
1
vote
2
answers
230
views
Improve saving to CSV file (C#)
I'm writing column data to CSV file:
string sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
string csvFile = "MyName.csv";
using (StreamWriter writer = new StreamWriter(csvFile))
{
...
1
vote
3
answers
283
views
C# Reuse StreamWriter or FileStream but change destination file
A little background...
Everything I'm about to describe up to my implementation of the StreamWriter is business processes which I cannot change.
Every month I pull around 200 different tables of data ...
0
votes
0
answers
28
views
Writing an ItemArray that contains NULLS
I'm trying to write a datarow out to a text file with delimiters between each value and this works fine until the SQL Table has any NULLs in it.
I can possibly just remove the NULL values from the ...
2
votes
2
answers
354
views
stream writer is not writing to JSON file in webapi
Im trying to write data in a JSON file using webapi but stream writer is not writing data to the file.
JSON File :
{
"Students": [
{
"id": 1,
"name": "Ravi&...
0
votes
1
answer
120
views
Is there a way to delete all lines of text from a .txt file using StreamReader/Writer?
I am using C# with Unity.
I have a text file in my assets that is updated by a void function via StreamWriter. I want to remove all lines of text from the file (making it blank) upon the execution of ...
1
vote
1
answer
135
views
Save and load a game by using StreamWriter and ReadWriter (C#)
I'm creating a small program which can save and load char array values. Then, I got stuck with two problems.
I have no idea how to make the program end after saving the data.
After loading the char ...