I have a C# .NET web project that I'm currently working on. What I'm trying to do is read some files that I dropped into a dir which is at the same level as fileReader.cs which is attempting to read them. On a normal desktop app the following would work:
我有一个C#.NET Web项目,我正在进行中。我正在尝试做的是读取一些文件,我放入一个与fileReader.cs处于同一级别的dir,它正在尝试读取它们。在普通的桌面应用程序上,以下方法可行:
DirectoryInfo di = new DirectoryInfo(./myDir);
However because it's a web project the execution context is different, and I don't know how to access these files?
但是因为它是一个Web项目,执行上下文是不同的,我不知道如何访问这些文件?
Eventually fileReader will be called in an installation routine. I intend to override one of the Installer.cs' abstract methods so will this affect the execution context?
最终将在安装例程中调用fileReader。我打算覆盖一个Installer.cs的抽象方法,这会影响执行上下文吗?
2 个解决方案
#1
4
Use Server.MapPath
to get the local path for the currently executing page.
使用Server.MapPath获取当前正在执行的页面的本地路径。
#2
3
Use the Server.MapPath method whichs maps the specified relative or virtual path to the corresponding physical directory on the server.
使用Server.MapPath方法将指定的相对或虚拟路径映射到服务器上的相应物理目录。
Server.MapPath("mydir/file.some")
This returns: C:\site\scripts\mydir\file.some
返回:C:\ site \ scripts \ mydir \ file.some
Script also can call the MapPath with full virtual path:
脚本也可以使用完整的虚拟路径调用MapPath:
Server.MapPath("/scripts/mydir/file.some")
Here is the link to the MSDN documentation of MapPath.
以下是MapPath的MSDN文档的链接。
#1
4
Use Server.MapPath
to get the local path for the currently executing page.
使用Server.MapPath获取当前正在执行的页面的本地路径。
#2
3
Use the Server.MapPath method whichs maps the specified relative or virtual path to the corresponding physical directory on the server.
使用Server.MapPath方法将指定的相对或虚拟路径映射到服务器上的相应物理目录。
Server.MapPath("mydir/file.some")
This returns: C:\site\scripts\mydir\file.some
返回:C:\ site \ scripts \ mydir \ file.some
Script also can call the MapPath with full virtual path:
脚本也可以使用完整的虚拟路径调用MapPath:
Server.MapPath("/scripts/mydir/file.some")
Here is the link to the MSDN documentation of MapPath.
以下是MapPath的MSDN文档的链接。