[英]read the content of file by getting it from dll
I have a C# project name as ("Test") which has a class and a folder contains a html file and my senior has compile this project into a dll. 我有一个C#项目名称(“测试”),它具有一个类,并且一个文件夹包含一个html文件,而我的上司已经将此项目编译为dll。
the content of the html file is = "Hello World" html文件的内容为=“ Hello World”
the class contains : 该类包含:
string that read the whole html file. 读取整个html文件的字符串。 context.Respone.Write(the string above).
context.Respone.Write(上面的字符串)。
I have another web project which has a page to call the method above by adding the test dll. 我有另一个Web项目,该页面具有通过添加测试dll来调用上述方法的页面。 The question is, how can I read the content of the html file by getting it from the dll ?
问题是,如何从dll中获取html文件的内容? So that the web page can display "Hello World"
使网页可以显示“ Hello World”
Put your file in Embedded resource and read it using code liek that 将您的文件放入嵌入式资源中,然后使用如下代码读取该文件:
public static string GetResourceFileContentAsString(string fileName)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Your.Namespace." + fileName;
string resource = null;
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
using (StreamReader reader = new StreamReader(stream))
{
resource = reader.ReadToEnd();
}
}
return resource;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.