VS 2005 C#のWindowsフォームアプリケーションでリソースファイルから取得するhtmlテンプレートがあります。C#でリソースファイルからテキストファイルを取得する方法VS.2005
プロジェクト内に/ 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();