79743750

Date: 2025-08-22 18:47:00
Score: 1
Natty:
Report link

We can get the File root path after deployment in Azure function using object

ExecutionContext executionContext
 public async Task<IActionResult> GetFiles([HttpTrigger(AuthorizationLevel.Function, nameof(HttpMethod.Get), Route = "Files/GetFilePath")] FilePathRequest request , ExecutionContext executionContext)
 {
     try
     {
         return await _bundleOrchestrator.GetFileData(request , executionContext.FunctionAppDirectory);            
     }
     catch (F9ApiException ex)
     {
         return new BadRequestErrorMessageResult(ex.ExceptionMessage) { StatusCode = ex.SourceStatusCode };
     }
 }   
public async Task<FilePathResponse> GetFileData( string rootPath)
{
    try
    {
        // Get the current working directory
         

        // Construct the path to the configuration folder and file
        string configFolder = "Configuration"; // Adjust as needed
        string configFileName = "NCPMobile_BundleConfig.json"; // Adjust as needed
        string filePath = Path.Combine(rootPath, configFolder, configFileName);

        // Check if the configuration file exists
        if (!File.Exists(filePath))
        {
            throw new FileNotFoundException($"Configuration file not found at: {filePath}");
        }

        // Define JSON serializer settings
        var jsonSettings = new Newtonsoft.Json.JsonSerializerSettings
        {
            MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore,
            NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
            MetadataPropertyHandling = Newtonsoft.Json.MetadataPropertyHandling.Ignore
        };

        // Read the JSON content asynchronously
        string jsonBundlesData = await File.ReadAllTextAsync(filePath);
        return jsonBundlesData; //Sample response

        // Proceed with processing jsonBundlesData as needed
    }
    catch (Exception ex)
    {
        // Handle exceptions appropriately
        throw new ApplicationException("Error occurred while retrieving bundle configuration.", ex);
    }
}

enter image description here

Reasons:
  • Blacklisted phrase (1): enter image description here
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: kalaivanan govindaraj