My company is creating a new website using IIS and Visual Studio 2015. It is composed of 3 solutions. The frontend(website), the backend(webapi), and the BL(businesslogic).
The BL is a .dll we create to pass data back and forth between our backend and our Databases as well as perform a couple other functions. The BL can also be built as a console application (I typically use that to run tests as I code).
One of my functions in the BL needs to open up an HTML file (This is the only function that needs to do this. No other functions in this solution need to open a file...yet)
var sr = File.OpenText("myFile.html")
//do stuff with sr
C:\Program Files (x86)\IIS Express
The file path you have specified only contains the file name not a full path. The path specified in
File.OpenText is relative to the current working directory as described in this MSDN article
When you debug the dll is copied into the bin folder so that becomes the working folder. When you deploy it live its in IIS Express folder so that is the working folder.
If you want the file to live else where enter an absolute path or a directory relative to the current working directory.
string path = @"c:\temp\myFile.html"; var sr = File.OpenText(path);
string path = @"~/relativefolder/somewhere/myFile.html"; var sr = File.OpenText(path);