How to grant rights to a JSON file we want to read?

864 Views Asked by At

I'm trying to read a JSON file with a web application on my localhost. I keep getting the same error:

Access to the path 'C:\Users\Admin\Documents\test\response.json' is refused. It seems like it can find the file but can't read it.

Here is how I try to read the file:

using (StreamReader reader = new StreamReader("C:\Users\Admin\Documents\test\response.json"))
{
    string fileContent = reader.ReadToEnd();
    JObject resultASJtoken = JObject.Parse(fileContent);
    return resultASJtoken;
}

I've also tried to change my right using icacls powershell command but it doesn't seems effective.

icacls "C:\Users\Admin\Documents\test\response.json" /grant Admin:F /T

If someone has an idea, I would really appreciate some help in this.

1

There are 1 best solutions below

0
On

I think you don't have access to the file because you don't have read permission due to its position. Move it to another folder manually and try again