Linked Questions
20 questions linked to/from Should I call Close() or Dispose() for stream objects?
-3 votes
1 answer
2k views
Closing the StreamReader [duplicate]
Is there any Using.System command or anything else, to close the automatically StreamReader. I've been closing the StreamReader like this e.g.: sr.Close();
2 votes
1 answer
149 views
Reasons to use Close over Dispose for a Stream? [duplicate]
Is there ever a valid reason to use the Close method on a stream instead of Dispose?
1 vote
1 answer
107 views
Necessary to explicitly close a stream in c# [duplicate]
I've come across some code like so: using (StreamReader myStream = new StreamReader(responseStream)) { response = myStream.ReadToEnd(); myStream....
1006 votes
21 answers
747k views
Is there a way to check if a file is in use?
I'm writing a program in C# that needs to repeatedly access 1 image file. Most of the time it works, but if my computer's running fast, it will try to access the file before it's been saved back to ...
455 votes
22 answers
1.3m views
Reading CSV file and storing values into an array
I am trying to read a *.csv-file. The *.csv-file consist of two columns separated by semicolon (";"). I am able to read the *.csv-file using StreamReader and able to separate each line by using the ...
65 votes
8 answers
45k views
Does Stream.Dispose always call Stream.Close (and Stream.Flush)
If I have the following situation: StreamWriter MySW = null; try { Stream MyStream = new FileStream("asdf.txt"); MySW = new StreamWriter(MyStream); MySW.Write("blah"); } finally { if (...
8 votes
4 answers
20k views
How to check if a StreamReader is still open?
I try to "wrap" a StreamReader in a class Fichier, with some extra methods and attributes. I want two things : The StreamReader opens automatically in the Fichier class; The StreamReader opens when ...
10 votes
3 answers
17k views
Do I need to dispose the FileStream object?
I am pretty depressed by my programming knowledge but do we really need to dispose FileStream Object ? Reason I am asking is because code is throwing "File being used by another process" exception ...
6 votes
4 answers
785 views
Finalization on StreamWriter and StreamReader
If I have this: StreamWriter cout = new StreamWriter("test.txt"); cout.WriteLine("XXX"); // here IOException... StreamReader cin = new StreamReader("test.txt"); string text = cin.ReadLine(); the clr ...
1 vote
2 answers
2k views
How to incorporate a text qualifier in a file name used as a variable?
I have a C# script which takes in two CSV files as input, combines the two files, performs numerous calculations on them, and writes the result in a new CSV file. These two input CSV file names are ...
0 votes
1 answer
2k views
StreamReader not accept string arguments?
Using the dotnet-cli (dotnet new, dotnet restore) with VScode, I made a new C# program. However, I can't seem to use the StreamReader properly. Here's the code. using System; using System.IO; ...
3 votes
2 answers
584 views
Who should dispose a Stream? The called method or the caller?
I'm writing an API that exports data to a Stream: public interface IExporter<in T> { Task ExportAsync(IEnumerable<T> inputs, Stream output); } Probably the various IExporter ...
1 vote
1 answer
618 views
C# The file under use even with close() , append doesn't work
I've been trying to write this in order to list my folders , the append part doesn't work and it rewrites the whole thing , also if i try to list something else without exiting the app it gives the ...
-2 votes
2 answers
2k views
Add a path to a code VB.net / visual basic
how do I add a path to a code where "HERE_HAS_TO_BE_A_PATH" is. When I do, Im getting an error message. The goal is to be able to specific the path where is the final text file saved. Thanks!...
1 vote
2 answers
2k views
Where is memory leak (Serialize object)
I have this method: public static string XmlSerialize<T>(T data) { string result; using (StringWriter stringWriter = new StringWriter()) { XmlWriterSettings settings = new ...