Getting dynamically web app name [or virtual dir name]

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MichaÅ‚ Januszczyk

    Getting dynamically web app name [or virtual dir name]

    How can I retrieve web application name (or virtual dir name)?
    (Actually I need physical root directory of web application)


    I want to open some files in web application root relative
    directory.
    Previously I used to open the files when client connected and
    thus could use the following code to retreive physical file location:

    string webAppRootDir = Server.MapPath( Request.Applica tionPath);

    Now I would like to open the files in application startup routine,
    where Request object is not available.

    when I call
    string webAppRootDir = Server.MapPath( "/");
    I get c:\intepub\wwwr oot (one level too "high")

    when calling:
    string webAppRootDir = Server.MapPath( "./");
    I get c:\intepub\wwwr oot\appname\[somedirectory] (one [or more] level too
    "deep")
    Actually this only works if at application startup somebody typed in browser:

    (specifically application name has not been suffixed with nested dir name)

    Is there any universal [working also without Request object]
    way to get web application physical root path?


    Note: I do not know virtual directory name, and must get it
    dynamically via code (but do not know how). If I know this,
    I might call the code:
    string webAppRootDir = Server.MapPath( "/"+virtDirNa me);


    Thanks for help
    Michal Januszczyk
  • Craig Deelsnyder

    #2
    Re: Getting dynamically web app name [or virtual dir name]

    On Sun, 29 Aug 2004 16:43:03 -0700, Michał Januszczyk
    <MichaJanuszczy k@discussions.m icrosoft.com> wrote:
    [color=blue]
    > How can I retrieve web application name (or virtual dir name)?
    > (Actually I need physical root directory of web application)
    >
    >
    > I want to open some files in web application root relative
    > directory.
    > Previously I used to open the files when client connected and
    > thus could use the following code to retreive physical file location:
    >
    > string webAppRootDir = Server.MapPath( Request.Applica tionPath);
    >
    > Now I would like to open the files in application startup routine,
    > where Request object is not available.
    >
    > when I call
    > string webAppRootDir = Server.MapPath( "/");
    > I get c:\intepub\wwwr oot (one level too "high")
    >
    > when calling:
    > string webAppRootDir = Server.MapPath( "./");
    > I get c:\intepub\wwwr oot\appname\[somedirectory] (one [or more] level too
    > "deep")
    > Actually this only works if at application startup somebody typed in
    > browser:
    > http://machinename/appName
    > (specifically application name has not been suffixed with nested dir
    > name)
    >
    > Is there any universal [working also without Request object]
    > way to get web application physical root path?
    >
    >
    > Note: I do not know virtual directory name, and must get it
    > dynamically via code (but do not know how). If I know this,
    > I might call the code:
    > string webAppRootDir = Server.MapPath( "/"+virtDirNa me);
    >
    >
    > Thanks for help
    > Michal Januszczyk[/color]

    Try
    Server.MapPath( "~")

    ~ maps to the root of the current application. It's an ASP.NET
    thing...can also be used most of the time in web.config, etc.

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET

    Comment

    Working...