Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read the content of file by getting it from dll

Tags:

c#

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.

the content of the html file is = "Hello World"

the class contains :

string that read the whole html file. context.Respone.Write(the string above).

I have another web project which has a page to call the method above by adding the test dll. The question is, how can I read the content of the html file by getting it from the dll ? So that the web page can display "Hello World"

like image 330
tester lol Avatar asked Nov 20 '25 06:11

tester lol


1 Answers

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;
    }
like image 189
fly_ua Avatar answered Nov 22 '25 20:11

fly_ua



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!