简体   繁体   中英

Reading files in a .NET project

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:

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?

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?

使用Server.MapPath获取当前正在执行的页面的本地路径。

Use the Server.MapPath method whichs maps the specified relative or virtual path to the corresponding physical directory on the server.

Server.MapPath("mydir/file.some")

This returns: C:\\site\\scripts\\mydir\\file.some

Script also can call the MapPath with full virtual path:

Server.MapPath("/scripts/mydir/file.some")

Here is the link to the MSDN documentation of MapPath .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM