http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath(v=vs.110).aspx
Using the MapPath method returns the actual file-system path to the root of your site.
質問
I am trying to read a file during Application_Start from my web application.
However at the Application_Start I am unable to get the file published to the Web Directory.
protected void Application_Start(object sender, EventArgs e)
{
using (StreamReader reader = File.OpenText("settings.json"))
{
}
}
The file was added to the web project, and set to Copy to Output Folder.
解決
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath(v=vs.110).aspx
Using the MapPath method returns the actual file-system path to the root of your site.