Skip to main content

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.

streamwriter
0 votes
1 answer
27 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(...
mz1378's user avatar
  • 2,430
0 votes
1 answer
206 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 ...
Akbar Shaik's user avatar
0 votes
1 answer
58 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 ...
Michał's user avatar
  • 23
-1 votes
2 answers
127 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 ...
BobKim's user avatar
  • 9
1 vote
1 answer
60 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 $...
POL's user avatar
  • 21
1 vote
2 answers
42 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 ...
ced's user avatar
  • 23
0 votes
1 answer
92 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 ...
Schmuli's user avatar
  • 21
1 vote
1 answer
124 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 ...
Altiubb's user avatar
  • 13
0 votes
1 answer
127 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 ...
AuthorBrotherGames's user avatar
-1 votes
1 answer
102 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 &...
Murrchalkina's user avatar
3 votes
2 answers
463 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 ...
Brian Kessler's user avatar
-1 votes
1 answer
152 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 ...
Humble Newbie's user avatar
-3 votes
1 answer
1k 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 ...
tin's user avatar
  • 15
1 vote
1 answer
359 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 ...
JKennedy's user avatar
  • 18.6k
0 votes
1 answer
118 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 ...
Kumas's user avatar
  • 45

15 30 50 per page