-1

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.

shashank shekhar
  • 132
  • 2
  • 15
  • Does this answer your question? [Azure functions reading custom files](https://stackoverflow.com/questions/58731103/azure-functions-reading-custom-files) – touchofevil May 29 '21 at 16:30
  • No it is not working even in local. It is fetching path= "C:\\Users\\shash\\Documents\\shopping-samples\\bin\\Debug\\netcoreapp3.1\\GoogleAuth\\shopping-samples" actual path should be=C:\Users\shash\Documents\shopping-samples – shashank shekhar May 29 '21 at 17:58

1 Answers1

0

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);
        }
    }
}
Cindy Pau
  • 13,085
  • 1
  • 15
  • 27