Reputation: 735
I am doing a simple file IO in MVC6. I have added System.IO
NuGet package. However, it gives me compile time error. VS IDE doesn't show any red mark when I type the code. The Close()
method also appears in intellisense. Please help!
StreamWriter writer = System.IO.File.CreateText("some_valid_path");
writer.WriteLine("test");
writer.Close();
StreamWriter does not contain a definition for 'Close' and no extension method 'Close' accepting a first argument of type 'StreamWriter' could be found (are you missing a using directive or an assembly reference?)
Thank you.
Upvotes: 7
Views: 526
Reputation: 438
Do you use the core CLR? The StreamWriter.Close
method are not available in core CLR. You can use Dispose
method replace.
You also can use using
statement:
using (var writer = System.IO.File.CreateText("your_path"))
{
writer.WriteLine("text");
}
Upvotes: 4