1

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?

4

2 回答 2

4

Use Server.MapPath to get the local path for the currently executing page.

于 2008-11-04T21:20:33.103 回答
3

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.

于 2008-11-04T21:22:27.297 回答