Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Streams and Data Processing Reading Data Console I/O

help plz

Challenge Task 2 of 2

Inside the using block, write the contents of the first line of the file to the Console. Bummer! Did you write the contents of the file to the Console? Restart Preview Get Help Recheck work CodeChallenge.cs

DirectoryInfo directory = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory()); string fileName = Path.Combine(directory.FullName, "secretmessage.txt"); using (var reader = new StreamReader(fileName))
{ Console.WriteLine(); } 1 DirectoryInfo directory = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory()); 2 string fileName = Path.Combine(directory.FullName, "secretmessage.txt"); 3 using (var reader = new StreamReader(fileName))
4 { 5 Console.WriteLine(); 6 }

CodeChallenge.cs
DirectoryInfo directory = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
string fileName = Path.Combine(directory.FullName, "secretmessage.txt");
using (var reader = new StreamReader(fileName))  
{
    Console.WriteLine();
}

3 Answers

Igor Kletsov
Igor Kletsov
7,556 Points
Console.WriteLine(reader.ReadLine());

C# Documentation

thank you so much igor

HIDAYATULLAH ARGHANDABI
HIDAYATULLAH ARGHANDABI
21,058 Points
DirectoryInfo directory = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
string fileName = Path.Combine(directory.FullName, "secretmessage.txt");
using (var reader = new StreamReader(fileName))  
{
    Console.WriteLine(reader.ReadLine());
}
Rick Hoekman
Rick Hoekman
9,494 Points

As far as I can tell you are not passing the fileName into the WriteLine function.

Try this and see if it will pass..

Console.WriteLine(fileName);

it's not working Rick

Sam Baines
Sam Baines
4,315 Points

Shawn no offence but you have 12000 points on treehouse, surely you must of by now learnt to follow the wording of the code challenges fully and also learnt how to search the documentation for languages when you get stuck like this.