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#

Cant write to file(working on a class project) C#

I cant write to file, not sure how/where to set _filePath Here is my current code:

using System; using System.Collections.Generic; using System.IO;

namespace weatherHumidity { // Loading weather data

class Program
{
    private static Stream _filePath;

    static void Main(string[] args)
    {
        string currentDirectory = Directory.GetCurrentDirectory();
        DirectoryInfo directory = new DirectoryInfo(currentDirectory);
        string fileName = Path.Combine(directory.FullName, "WeatherData.csv");
        List<string[]> fileContents = ReadWeatherData(fileName);


    }
    // Reading weather Data
    public static string ReadFile(string fileName)
    {
        using (var reader = new StreamReader(fileName))
        {
            return reader.ReadToEnd();
        }
    }
    public static List<string[]> ReadWeatherData(string fileName)

    {
        List<string[]> weatherHumidity = new List<string[]>();
        using (var reader = new StreamReader(fileName))
        {
            string line = "";
            reader.ReadLine();
            Console.ReadLine();
            while ((line = reader.ReadLine()) != null)
            {
                WeatherHumidity weatherdata = new WeatherHumidity();
                string[] values = line.Split(',');
                weatherdata.Temps = values[8];
                weatherHumidity.Add(values);

            }
        }
            return weatherHumidity;
    }

    //Writng some information to a file

    public static void WriteToFile(string value)
    {
        using (StreamWriter writer = new StreamWriter(_filePath))
        {
            writer.Write(value);
        }
        Console.ReadLine();
    }
}

}

Thanks for any help.