Kenny
Kenny

Reputation: 849

How to access Azure Linux web app path file

Trying to access file on path - wwwroot/templates/file.txt. It works using -_hostingEnvironment.ContentRootPath + "\templates\file.txt" on windows but same path says file does not exists. What Am I missing

Upvotes: 1

Views: 879

Answers (1)

Fei Han
Fei Han

Reputation: 27803

Trying to access file on path - wwwroot/templates/file.txt.

The following code snippet work for me, you can refer to it.

var filepath = Path.Combine(_hostingEnvironment.ContentRootPath, "templates", "file.txt");

var mes = "test message";

if (System.IO.File.Exists(filepath))
{
    using (StreamReader file = new StreamReader(filepath))
    {
        mes = file.ReadLine();
    }
}

ViewBag.fp = filepath;

ViewBag.mes = mes;

return View();

And please make sure the file is really existing under that folder on your server.

enter image description here

Test Result

enter image description here

Upvotes: 1

Related Questions