简体   繁体   中英

Azure function Path issue after published

I am using azure function app V3 and I am reading an excel from Data folder in the same project. I have set Copy-always for excel and it's been copied into bin folder. So In code I'm referring path as var binDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

but after publishing the Data folder is out side bin folder and my code is unable to find the excel. Path of my excel after publish:- C:\home\site\wwwroot\Data

path my code is looking at:- C:\home\site\wwwroot\bin\Data

Kudu Path

Is there a generic way to make path to work in local and after published to azure.

Any help is appreciated.! Thanks in advance.

Try to add ExecutionContext context parameter in your function method, the use the code below:

    public static void Run(other parameter, ExecutionContext context)
    {
        string templatePath = Path.Combine(context.FunctionAppDirectory, "Data");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM