Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.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# 根文件夹文件未进入应用程序代码文件夹_C#_Asp.net - Fatal编程技术网

C# 根文件夹文件未进入应用程序代码文件夹

C# 根文件夹文件未进入应用程序代码文件夹,c#,asp.net,C#,Asp.net,我正在使用下面的代码获取app_代码文件夹中的根文件夹html文件 using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/EMailTemplate.html"))) { ... } 但是我也犯了同样的错误 找不到对象引用 有人能帮我吗?从你写第一行的方式,我可以看出你使用的是一个不在代码背后的类。即便如此,类似的规则也适用于Server.MapPath的工作方式 我认为您需要去掉

我正在使用下面的代码获取app_代码文件夹中的根文件夹html文件

using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/EMailTemplate.html")))
{
...
}
但是我也犯了同样的错误

找不到对象引用


有人能帮我吗?

从你写第一行的方式,我可以看出你使用的是一个不在代码背后的类。即便如此,类似的规则也适用于Server.MapPath的工作方式

我认为您需要去掉tilde并用相对路径替换它。看