Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get File that was `copied to output directory` in a class library

Tags:

c#

.net

In a class library, I have a file that is set to copy to output directory at 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 do I read this file?

like image 242
Dave Avatar asked Nov 15 '22 03:11

Dave


1 Answers

Use this:

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

If you place the above code in an MVC controller action you can change Server to this.HttpContext.Server to work

like image 86
Eduardo Campañó Avatar answered Dec 15 '22 06:12

Eduardo Campañó