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! Your code could not be compiled. Please click on "Preview" to view the compiler errors. Restart Preview Get Help Recheck work CodeChallenge.cs

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(fileName); 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(fileName);
}

1 Answer

Steven Parker
Steven Parker
231,198 Points

:point_right: It looks like you have a couple of issues:

  • you have a stray semicolon at the end of the line with the using statement (causing the compiler error)
  • the challenge wants you to write out the first line of the file, not the file's name

If you're not sure how to do the second item, you might want to review the video for Console I/O, starting around time index 03:45.