How to get local file system path in azure websites

后端 未结 5 641
闹比i
闹比i 2020-12-31 20:25

I have a file hosted on the disk along with my website that I want to read .Not sure how do I access the file when I use System.Environment.CurrentDirectory it point to a D

5条回答
  •  有刺的猬
    2020-12-31 20:54

    There is an environment variable called HOME in your website's environment that will get you part way there.

    You can access it using razor syntax or in code (C#). For example, suppose you have a file called data.txt that is at the root of your site with the default document and the rest of your files. You could get it's full path like this.

    @{ var dataFileName = Environment.GetEnvironmentVariable("HOME").ToString() + "\\site\\wwwroot\\data.txt"; }
    

    You can find this out on your own using the Site Control Management/"Kudu". For example, if your website is contoso.azurewebsites.net, then simply navigate to contoso.scm.azurewebsites.net. In here you can learn all about the file system and environment variables available to your website.

提交回复
热议问题