I have a html template that I want to retrieve from the resources file in a VS 2005 C# windows form application.
I've created a folder called /html/ within the project, which has one file in it called template.html.
I've added the file to my resources. I see its name just as template, and it's filepath is the fully qualified filename (c:/.../project/html/template.html). It is saved as TEXT rather than binary.
I've tried many methods to extract this file, but each time I get a null returned. What am I missing?
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();