Get current folder path of http trigger function in Azure in dotnet core

522 views Asked by At

I am creating a http trigger function in dotnet core where I need to find current folder path of my project shopping-samples.Though i am able to execute below code in local in vs code. private static readonly string defaultPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "shopping-samples"); How i can get the folder path in Azure for this http trigger function. The path in local is showing :C:\Users\shash\Documents\shopping-samples and it is working perfectly fine in local. Please help.

1

There are 1 answers

1
Cindy Pau On BEST ANSWER

Try below code to get current folder path:

using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace FunctionApp8
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log,
            ExecutionContext context)
        {
            return new OkObjectResult(context.FunctionAppDirectory);
        }
    }
}