Get the file that was "copied to the output directory" in the class library

In the class library, I have a file that is installed to be copied to the output directory in NewFolder1/HTMLPage1.htm.

I tried this:

var foo = File.ReadAllText("NewFolder1/HTMLPage1.htm");

But the error is:

ould not find a part of the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\NewFolder1\HTMLPage1.htm'.

How can I read this file?

+5
source share
1 answer

Use this:

var foo = File.ReadAllText(Server.MapPath("NewFolder1/HTMLPage1.htm"));

If you put the above code in an MVC controller action, you can change Server to that. HttpContext.Server to work

+1
source

All Articles