即使在 Visual studio C# 中添加了文件,系统 IO 异常
System IO exception even though file is added in Visual studio C#
我有一个项目,我在其中添加了一个 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 方法为您提供文件在服务器计算机上的物理路径。
我有一个项目,我在其中添加了一个 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 方法为您提供文件在服务器计算机上的物理路径。