У меня есть html-шаблон, который я хочу получить из файла ресурсов в приложении формы Windows VS # C.
Я создал папку с именем / html / внутри проекта, в которой есть один файл с именем template.html.
Я добавил файл в мои ресурсы. Я вижу его имя как шаблон, а путь к файлу - это полное имя файла (c: /.../ project / html / template.html). Он сохраняется как текст, а не как двоичный файл.
Я пробовал много способов извлечь этот файл, но каждый раз, когда я получаю ноль, возвращается. Чего мне не хватает?
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();