How to get local file system path in azure websites

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

    For testability, I use below code.

    string path = "";
    if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOME")))
        path = Environment.GetEnvironmentVariable("HOME") + "\\site\\wwwroot\\bin";
    else
        path = ".";
    path += "\\Resources\\myfile.json";
    

    In above example, I added myfile.json file to Resources folder in a project with Content and Copy if newer property setting.

提交回复
热议问题