Reputation: 425
I have a project into which I added a JSON file, but when I try to read the file in code I get this error.
Could not find file 'C:\\Program Files (x86)\\IIS Express\\client_secret.json'.
"ExceptionType": "System.IO.FileNotFoundException"
I have the file added in like this.
I can access it when I copy the full path and then read it.
Upvotes: 0
Views: 461
Reputation: 176886
its Asp.NEt or WEBAPI, i.e. its Web application you can access path by using Server.MapPath
method.
Example : Server.MapPath("~/script/data.txt")
//this locate file in your script folder on sever
for the folder under than website you need to do like this
Server.MapPath(~/client._secret.json) //here ~ sign means relative path from root
Server.MapPath method gives you physical path of your file on server machine.
Upvotes: 2