Search code examples
c#jsonasp.net-corerelative-path

How to load json file in c# from relative path?


I have a problem with localizing the JSON file inside my folder. I have a test class, and in the same directory, I have a JSON file. So what I want to achieve is to retrieve the JSON file with a relative path.

enter image description here

And the thing that I have tried is this

 var jsonString = File.ReadAllText("\\TemplateUrlOk.json");

UPDATE

This is the structure of the test project.

enter image description here


Solution

  • I will be answering my question, hence I found the problem.

    @ADyson mentioned that the JSON file needs to be copied in the directory when the project builds, which I did. However, it was in another folder called EmailController and the filename.