How to get another folder in same Project in Azure Linux Function

85 views Asked by At

Below is my project Structure:

ProjectX
- www (folder)
- - index.html (target file that want to access)
- MyFunc.cs (Function)
- local.settings.json

After I deployed to Azure Linux Function, I could not find a way to find index.html.

I tried below paths already:

  1. /home/site/wwwroot/
  2. /home/site/wwwroot/MyFunc/
  3. /home/site/
  4. /home/site/wwwroot/bin/
  5. /home/site/wwwroot/bin/runtimes

Below is my coding for checking file:

public static async Task Run([ServiceBusTrigger(ServiceBusContext.MyQueueName, Connection = "ServiceBus")] Message msg, ILogger log)
{
    // change to different paths
    var testDir1 = new DirectoryInfo($@"/home/site/wwwroot/");
    FindFileInfo(testDir1, log);
}

public static void FindFileInfo(DirectoryInfo dir, ILogger log)
{
    FileInfo[] files = dir.GetFiles();
    foreach (FileInfo file in files)
    {
        log.LogInformation("Check File, RootDir=" + dir.FullName + ", File: {0}", file.Name);
    }
}
1

There are 1 answers

0
DaiKeung On

Can use context.FunctionAppDirectory:

public static async Task Run([ServiceBusTrigger(ServiceBusContext.MyQueueName, Connection =
"ServiceBus")] Message msg, ILogger log, ExecutionContext context)
{
    var path = Path.Combine(context.FunctionAppDirectory, "www", "index.html");
}