Reputation: 5098
Why is this not working ?
StreamReader m = new StreamReader("../folder1/email.html", System.Text.Encoding.UTF8);
code file and html file are in diff folders so I that its some path issue but its not because I just now copied this html file in the same folder where this code file is and changed code to:
StreamReader m = new StreamReader("email.html", System.Text.Encoding.UTF8);
still not working.. What's wrong? Is the syntax wrong or what?
Upvotes: 1
Views: 2110
Reputation: 12110
You are probably not reading it ...try this ...put the file in your Bin/Debug directory and...
StreamReader m = new StreamReader("email.html", System.Text.Encoding.UTF8);
Console.Write(m.ReadToEnd());
Console.ReadLine();
Upvotes: 1
Reputation: 5165
If you use a relative path it will be relative to the bin/Debug or bin/Release folder, not the project folder where your code file is, so try:
m= new StreamReader("../../email.html", System.Text.Encoding.UTF8);
Upvotes: 2
Reputation: 1039498
You say that there's no exception with your code. This means that the file is successfully opened for reading. I suspect that you are not reading anything from this StreamReader
, you are simply instantiating it and probably not releasing.
Make sure you dispose this stream or you might leak handles. If all you need to do is read the file contents you could use the ReadAllText method:
string contents = File.ReadAllText("email.html");
If the file is not found you will get an exception.
Upvotes: 1