VS 2005 C#Windowsフォームアプリケーションのリソースファイルから取得したいhtmlテンプレートがあります。
プロジェクト内に/html/というフォルダーを作成しました。このフォルダーには、template.htmlというファイルが1つあります。
ファイルをリソースに追加しました。その名前はテンプレートと同じように表示され、ファイルパスは完全修飾ファイル名(c:/.../project/html/template.html)です。バイナリではなくTEXTとして保存されます。
このファイルを抽出するために多くの方法を試しましたが、毎回nullが返されます。私は何が欠けていますか?
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();