简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM