-1

I am working on a problem that requires me to read from two different .Json files depending on URL of the webpage I can't seem to find any other way to read other than the Iconfiguration. is there any way that I can determine a path for Configuration? like (/site/webURL/appsetting.json/) then pick the name of the value I would like to get (_configuration["privacy:GDPR"]) I don't have a problem reading from normal appsettings. I just want to know how I have read information from a .json with a certain path

public static string Getjsonvalue(string hostName = "")
        {
            string hostNam = string.IsNullOrEmpty(hostName) ? _options.Value.Paths.Defaultsite : hostName.Replace('-', '_').Replace('.', '_');

            var rootPath = ("/sites/" + GetSite(hostName) + "/appsetting.json").Replace('\\', '/');
            var Value =  find configuration["privacy:GDPR"] in rootPath// where i need help
            return Value;
        }
  • This question has been already answered [Question](https://stackoverflow.com/questions/49046847/how-can-i-add-a-custom-json-file-into-iconfiguration) – Matt Qafouri May 21 '21 at 06:14
  • @Majid that doesn't answer my question. I want to be able to use 3 or 4 config files at the same time by giving my application a path. – AverageGuyIsaac May 21 '21 at 14:17

1 Answers1

1

one way to read file by path can be like this :

string contentRootPath = _hostingEnvironment.ContentRootPath;
var JsonFile = System.IO.File.ReadAllText( contentRootPath + "/yourJsonFile.json");
Matt Qafouri
  • 1,449
  • 2
  • 12
  • 26