Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 即使在Visual studio C中添加了文件,系统IO异常#_C#_Filenotfoundexception - Fatal编程技术网

C# 即使在Visual studio C中添加了文件,系统IO异常#

C# 即使在Visual studio C中添加了文件,系统IO异常#,c#,filenotfoundexception,C#,Filenotfoundexception,我有一个项目,在其中添加了一个JSON文件,但是当我试图用代码读取该文件时,我得到了这个错误 Could not find file 'C:\\Program Files (x86)\\IIS Express\\client_secret.json'. "ExceptionType": "System.IO.FileNotFoundException" 我已经像这样添加了文件 我可以在复制完整路径并读取它时访问它 其Asp.NEt或WEBAPI,即其Web应用程序,您可以使用Server.Ma

我有一个项目,在其中添加了一个JSON文件,但是当我试图用代码读取该文件时,我得到了这个错误

Could not find file 'C:\\Program Files (x86)\\IIS Express\\client_secret.json'.
"ExceptionType": "System.IO.FileNotFoundException"
我已经像这样添加了文件

我可以在复制完整路径并读取它时访问它


其Asp.NEt或WEBAPI,即其Web应用程序,您可以使用
Server.MapPath
方法访问路径

示例:
Server.MapPath(“~/script/data.txt”)
//此文件位于服务器上的脚本文件夹中

对于网站下的文件夹,您需要这样做

Server.MapPath(~/client._secret.json) //here ~ sign means relative path from root 

Server.MapPath方法为您提供服务器计算机上文件的物理路径

其Asp.NEt或WEBAPI,即其Web应用程序,您可以使用
Server.MapPath
方法访问路径

示例:
Server.MapPath(“~/script/data.txt”)
//此文件位于服务器上的脚本文件夹中

对于网站下的文件夹,您需要这样做

Server.MapPath(~/client._secret.json) //here ~ sign means relative path from root 

Server.MapPath方法为您提供服务器计算机上文件的物理路径

@PranayRana一开始它不起作用,因为它给了我一个错误,说一个文件夹丢失了-api。所以我添加了那个文件夹并将文件添加到其中。现在它可以工作了。进行编辑以回答类似添加Server.MapPath(~/client.\u secret.json)的问题,因为这对我很有帮助。done updated…@PranayRana它一开始不起作用,因为它给了我一个错误,说缺少一个文件夹-api。所以我添加了那个文件夹并将文件添加到其中。现在它可以工作了。做一个编辑来回答这个问题,比如添加Server.MapPath(~/client.\u secret.json),因为这正是帮助我完成更新的原因。。。。