Skip to content
Advertisement

How to access Azure Linux web app path file

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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement