Search code examples
c#streamreadernotsupportedexception

I am unable to read content from .txt file using StreamReader class of c#


Here is my code..I am trying to read data from .txt file which was stored in music folder. But i am getting some error like, System.NotSupportedException. The given path's format is not supported.

Please help...........

string path = @"Music:\streamfile.txt";

using (StreamReader sr = File.OpenText(path))
{
    String s = "";

    while ((s = sr.ReadLine()) != null)
    {
        Console.WriteLine(s);
    }
}
Console.ReadLine();

Solution

  • There is a list with 'special' folders somewhere but you can construct it yourself:

      string path = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"),
               "Music", "streamfile.txt");