如何从 ASP.NET 的 App_Code 文件夹中的类访问网站根目录的路径?我试过:
StreamReader sr = new StreamReader("../Questions.aspx");
但它给了我 Program Files 中的路径...
那我该怎么做呢?至少我认为我可以从 App_Code 文件夹导航到目录中的上层文件夹
编辑:我不是在开发网络应用程序,而是在开发网站
最佳答案
尝试使用
string filePath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath;
StreamReader sr = new StreamReader(filePath + @"\Questions.aspx");
关于c# - 在 asp.net 中使用 streamreader 访问站点目录路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7839953/