我在Resource1.resx中有一个HTML文件。现在,我必须使用StreamReader
的html文件内容。我该怎么办?
以下是html文件的内容:
<html>
<body>
<table>
<tr>
<td>$$name$$</td>
</tr>
<tr>
<td>$$subject$$</td>
</tr>
</table>
</body>
</html>
我在cs中使用以下代码:
var assembly = Assembly.GetExecutingAssembly();
string resourceName = (string)GetGlobalResourceObject("Resource1", "MyTemplate");
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
string readfile = reader.ReadToEnd();
string mystring = "";
mystring = readfile;
mystring = mystring.Replace("$$Member$$", name);
mystring = mystring.Replace("$$Subject$$", TxtSubject.Text);
return mystring;
}
但stream
会返回null
。
答案 0 :(得分:0)
var assembly = Assembly.GetExecutingAssembly();
string resourceName = (string)HttpContext.GetGlobalResourceObject("Resource1", "MyTemplate");
string mystring = "";
mystring = resourceName;
mystring = mystring.Replace("$$Member$$", name);
mystring = mystring.Replace("$$Subject$$", TxtSubject.Text);
return mystring;