我有一个html模板,我想从VS 2005 C#窗体表单应用程序中的资源文件中检索。如何从C#中的资源文件中检索文本文件VS.2005
我在项目中创建了一个名为/ html /的文件夹,该文件夹中有一个名为template.html的文件。
我已将该文件添加到我的资源中。我将它的名称看作模板,它的文件路径是完全限定的文件名(c:/.../project/html/import.html)。它被保存为TEXT而不是二进制。
我试过很多方法来提取这个文件,但每次我得到一个空返回。我错过了什么?
Type t = GetType();
Assembly a = Assembly.GetAssembly(t);
string file = "html.template.html"; // I've tried template and template.html
string resourceName = String.Concat(t.Namespace, ".", file);
Stream str = a.GetManifestResourceStream(resourceName);
if (str == null) // It fails here - str is always null.
{
throw new FileLoadException("Unrecoverable error. Template could not be found");
}
StreamReader sr = new StreamReader(str);
htmlTemplate = sr.ReadToEnd();