c# - 在 asp.net 中使用 streamreader 访问站点目录路径

标签 c# asp.net streamreader

如何从 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/

相关文章:

asp.net - View 状态异常 View 状态 MAC 验证失败

asp.net core 2.0 在输出文件夹中有 Microsoft.VisualStudio.Web.CodeGeneration 文件

c# - StreamReader.Read 返回\0

c# - 我可以让 StreamReader.EndOfStream 在第一次读取文件后返回 false 吗?

C# 服务器线程分配

c# - 无法为 'ApplicationUser' 创建 DbSet,因为此类型未包含在上下文的模型中

asp.net - __doPostBack() 是否有可能发送 GET 请求?

c# - 读取文本文件跳过一堆行然后继续其他行

c# - 在 SQL Azure 中保存 XML 文件

c# - 将 float 格式的 char[] 转换为 float