繁体   English   中英

如何访问 Azure Linux Web 应用程序路径文件

[英]How to access Azure Linux web app path file

试图访问路径上的文件 - wwwroot/templates/file.txt。 它在 Windows 上使用 -_hostingEnvironment.ContentRootPath + "\\templates\\file.txt" 工作,但相同的路径表示文件不存在。 我错过了什么

试图访问路径上的文件 - wwwroot/templates/file.txt。

以下代码片段对我有用,您可以参考。

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();

并且请确保该文件确实存在于您服务器上的该文件夹下。

在此处输入图片说明

测试结果

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM