通过从dll中获取文件来读取文件的内容

read the content of file by getting it from dll

我有一个名为 ("Test") 的 C# 项目,它有一个 class 和一个包含 html 文件的文件夹,我的前辈已经将这个项目编译成一个 dll。

html文件的内容是="Hello World"

class 包含:

读取整个 html 文件的字符串。 context.Respone.Write(上面的字符串)。

我有另一个 web 项目,它有一个页面可以通过添加测试 dll 来调用上面的方法。问题是,如何通过从 dll 获取 html 文件的内容来读取它?这样网页才能显示"Hello World"

将您的文件放入嵌入式资源并使用

的代码库读取它
    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;
    }