How to get local file system path in azure websites

后端 未结 5 692
闹比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:53

    You can do it using the below code.

    string fullFilePath = Environment.GetEnvironmentVariable("HOME") != null
        ? Environment.GetEnvironmentVariable("HOME") + @"\site\wwwroot\test.txt" //It will give the file directory path post azure deployment
        : Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())) + @"\test.txt";//It will give the file directory path in dev environment.
    

提交回复
热议问题