Click here to Skip to main content
15,917,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
With the RC1 of .NET Core I went to investigate the most burning question in the back of my mind!
Can I open a damn FileStream to a file on the disk with .NET Core?
(And by that I mean anywhere, like "C:\temp\a.txt" and not just in $user\AppData !!!)

So I opened visual studio 2015, clicked new project > web > Console Application package (yes "web" is where the native app is!!)

then I typed "new FileStream" and looked at the helpful intellisense advice.

And it's where I got confused....

"new FileStream(....)" is:
- available for "DNX 4.5.1"
- NOT available for "DNX Core 5.0"

When I tried to compile
using (var s = new FileStream(@"c:\temp\a.txt", FileMode.Create))
using (var sw = new StreamWriter(s))
    sw.WriteLine("it worked!");

I got
Program.cs(13,32,13,42): DNX Core 5.0 error CS0246: The type or namespace name 'FileStream' could not be found (are you missing a using directive or an assembly reference?)
Program.cs(13,61,13,69): DNX Core 5.0 error CS0103: The name 'FileMode' does not exist in the current context

And YES I am using System.IO; it's an "issue" with ".NET Core"....

what does that means?!

What I have tried:

created a new .NET Core web app and looked at intellisense information
Updated 14-Feb-16 14:13pm

1 solution

I found this : .NET Core and FileStream[^]

Seems you only get the basics and have to load nuget packages for the extras.
Share this answer
Super Lloyd 15-Feb-16 0:54am    
Awesome Mehdi!!
I was suffering of a severe case of Mondayitis!
It was my question and I ignored the answer!
The Nuget package fixed it!
It now compiles.... And even better, it runs! :)
Mehdi Gholam 15-Feb-16 1:03am    
Cheers! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900