Reputation: 3
I have a project in MVC and I want to read a .txt file in the project root.
Because I will send this solution to my partner and he will just click run. I have tried to use Combine
code but I have an error like "path does not exist".
var path = Path.Combine(Directory.GetCurrentDirectory(), @"\CustomerFile-2015-07-30T1510.txt");
System.IO.StreamReader file = new System.IO.StreamReader(path);
Upvotes: 0
Views: 1896
Reputation: 22945
Since it is an ASP.NET MVC project, I would suggest to use Server.MapPath("~")
to get the root of your ASP.NET Application.
var root = Server.MapPath("~");
var path = Path.Combine(root, @"CustomerFile-2015-07-30T1510.txt");
System.IO.StreamReader file = new System.IO.StreamReader(path);
Upvotes: 3