Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于读取/写入静态文件的Azure路径_Azure_Asp.net Core_Deployment - Fatal编程技术网

用于读取/写入静态文件的Azure路径

用于读取/写入静态文件的Azure路径,azure,asp.net-core,deployment,Azure,Asp.net Core,Deployment,我正在尝试在Azure中读取/写入一个文件,并将其放入wwwroot\words.txt-文件夹中 private readonly string _Filename = @"wwwroot\words.txt"; System.IO.FileNotFoundException:找不到文件“D:\home\site\wwwroot\wwwroot\words.txt”。 文件名:“D:\home\site\wwwroot\wwwroot\words.txt” System.IO

我正在尝试在Azure中读取/写入一个文件,并将其放入
wwwroot\words.txt
-文件夹中

        private readonly string _Filename = @"wwwroot\words.txt";
System.IO.FileNotFoundException:找不到文件“D:\home\site\wwwroot\wwwroot\words.txt”。 文件名:“D:\home\site\wwwroot\wwwroot\words.txt”

System.IO.FileNotFoundException:找不到文件“D:\home\site\wwwroot\words.txt”。 文件名:“D:\home\site\wwwroot\words.txt”

System.IO.FileNotFoundException:找不到文件“D:\home\site\wwwroot\words.txt”。 文件名:“D:\home\site\wwwroot\words.txt”

基于此,

System.IO.FileNotFoundException:找不到文件“D:\home\site\wwwroot\words.txt”。 文件名:“D:\home\site\wwwroot\words.txt”

在本地,它是有效的。没有使用数据库,我会错过什么吗

我正在尝试在Azure中读取/写入一个文件,并将其放入wwwroot\words.txt文件夹中

为了满足您的需求,您可以尝试以下代码片段

public class HomeController : Controller
{
    private IWebHostEnvironment _env;

    public HomeController(ILogger<HomeController> logger, IWebHostEnvironment env)
    {
        _logger = logger;
        _env = env;
    }
    public IActionResult ReadTxt()
    {
        var path = Path.Combine(_env.ContentRootPath, "words.txt");

        using (FileStream fs = System.IO.File.Create(path))
        {
            byte[] content = new UTF8Encoding(true).GetBytes("Hello World");

            fs.Write(content, 0, content.Length);
        }

        string text = System.IO.File.ReadAllText(path);

        ViewData["path"] = path;

        ViewData["mes"] = text;

        return View();
    }
公共类HomeController:控制器
{
私人IwebhostenEnvironment;
公共家庭控制器(ILogger记录器、IWebHostEnvironment环境)
{
_记录器=记录器;
_env=env;
}
公共IActionResult ReadTxt()
{
var path=path.Combine(_env.ContentRootPath,“words.txt”);
使用(FileStream fs=System.IO.File.Create(path))
{
byte[]content=新的UTF8Encoding(true).GetBytes(“Hello World”);
fs.Write(content,0,content.Length);
}
string text=System.IO.File.ReadAllText(路径);
ViewData[“路径”]=路径;
ViewData[“mes”]=文本;
返回视图();
}
查看页面

<h1>ReadTxt</h1>

Read file form @ViewData["path"]
<hr />
@ViewData["mes"]
ReadTxt
读取文件格式@ViewData[“路径”]

@ViewData[“mes”]
测试结果

此外,如果
words.txt
存储在中,如下所示

要访问它,可以使用
var path=path.Combine(_env.WebRootPath,“words.txt”);

我正在尝试在Azure中读取/写入一个文件,并将其放入wwwroot\words.txt文件夹中

为了满足您的需求,您可以尝试以下代码片段

public class HomeController : Controller
{
    private IWebHostEnvironment _env;

    public HomeController(ILogger<HomeController> logger, IWebHostEnvironment env)
    {
        _logger = logger;
        _env = env;
    }
    public IActionResult ReadTxt()
    {
        var path = Path.Combine(_env.ContentRootPath, "words.txt");

        using (FileStream fs = System.IO.File.Create(path))
        {
            byte[] content = new UTF8Encoding(true).GetBytes("Hello World");

            fs.Write(content, 0, content.Length);
        }

        string text = System.IO.File.ReadAllText(path);

        ViewData["path"] = path;

        ViewData["mes"] = text;

        return View();
    }
公共类HomeController:控制器
{
私人IwebhostenEnvironment;
公共家庭控制器(ILogger记录器、IWebHostEnvironment环境)
{
_记录器=记录器;
_env=env;
}
公共IActionResult ReadTxt()
{
var path=path.Combine(_env.ContentRootPath,“words.txt”);
使用(FileStream fs=System.IO.File.Create(path))
{
byte[]content=新的UTF8Encoding(true).GetBytes(“Hello World”);
fs.Write(content,0,content.Length);
}
string text=System.IO.File.ReadAllText(路径);
ViewData[“路径”]=路径;
ViewData[“mes”]=文本;
返回视图();
}
查看页面

<h1>ReadTxt</h1>

Read file form @ViewData["path"]
<hr />
@ViewData["mes"]
ReadTxt
读取文件格式@ViewData[“路径”]

@ViewData[“mes”]
测试结果

此外,如果
words.txt
存储在中,如下所示

要访问它,您可以使用
var path=path.Combine(_env.WebRootPath,“words.txt”);

请参阅此。请参阅此。
<h1>ReadTxt</h1>

Read file form @ViewData["path"]
<hr />
@ViewData["mes"]