views:

106

answers:

2

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  A: 

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

Omer van Kloeten
+3  A: 

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.

splattne