How to get Full Path of current directory ? (ASP.net)

Discussion in 'ASP .Net' started by PHaroZ, Nov 26, 2003.

  1. PHaroZ

    PHaroZ Guest

    Hi,

    I want to retrieve the complete full path to the directory
    of my current page but i don't find how to do that.
    For example i want : D:\myWebSite\firstDotNetWebApp\dir1\

    I tried "AppDomain.CurrentDomain.BaseDirectory" but it's
    return only the path to my WebApplication, ex :
    D:\myWebSite\firstDotNetWebApp\

    Some how to do that ?

    thx
    PHaroZ, Nov 26, 2003
    #1
    1. Advertising

  2. PHaroZ

    SSW Guest

    Server.MapPath("MyWebSite");

    HTH

    Thanks,

    sswalia

    "PHaroZ" <> wrote in message
    news:0bff01c3b403$49aa6070$...
    > Hi,
    >
    > I want to retrieve the complete full path to the directory
    > of my current page but i don't find how to do that.
    > For example i want : D:\myWebSite\firstDotNetWebApp\dir1\
    >
    > I tried "AppDomain.CurrentDomain.BaseDirectory" but it's
    > return only the path to my WebApplication, ex :
    > D:\myWebSite\firstDotNetWebApp\
    >
    > Some how to do that ?
    >
    > thx
    SSW, Nov 26, 2003
    #2
    1. Advertising

  3. PHaroZ

    Rob Meade Guest

    "PHaroZ" wrote...

    > Some how to do that ?


    Server.MapPath( Path)

    ** Copied from a search in Visual Studio for mappath **

    For the examples below, the file Data.txt is located in the directory,
    C:\Inetpub\Wwwroot\Script, along with the Test.asp file that contains the
    following scripts. The C:\Inetpub\Wwwroot directory is set as the server's
    home directory.

    The following example uses the server variable PATH_INFO to map the physical
    path of the current file.

    <%= Server.MapPath(Request.ServerVariables("PATH_INFO"))%><BR>

    The preceding script produces the following output:

    c:\inetpub\wwwroot\script\test.asp<BR>

    Because the path parameters in the following examples do not start with a
    slash character, they are mapped relative to the current directory, in this
    case C:\Inetpub\Wwwroot\Script.

    <%= Server.MapPath("data.txt")%><BR>
    <%= Server.MapPath("script/data.txt")%><BR>

    The preceding scripts produce the following output:

    c:\inetpub\wwwroot\script\data.txt<BR>
    c:\inetpub\wwwroot\script\script\data.txt<BR>

    The next two examples use the slash characters to specify that the path
    returned should be looked up as complete virtual paths on the server.

    <%= Server.MapPath("/script/data.txt")%><BR>
    <%= Server.MapPath("\script")%><BR>

    The preceding scripts produce the following output:

    c:\inetpub\wwwroot\script\data.txt<BR>
    c:\inetpub\wwwroot\script<BR>

    The following examples demonstrate how you can use either a forward slash
    (/) or a backslash (\) to return the physical path to the home directory of
    the Web site root.

    <%= Server.MapPath("/")%><BR>
    <%= Server.MapPath("")%><BR>

    The preceding scripts produce the following output:

    c:\inetpub\wwwroot<BR>
    c:\inetpub\wwwroot<BR>

    The following example demonstrates how you can use relative paths to return
    the relative physical path to the page that is being viewed in the Web
    browser.

    <%= Server.MapPath("../")%><BR>
    <%= Server.MapPath("..")%><BR>

    Hope this helps.

    Regards

    Rob
    Rob Meade, Nov 26, 2003
    #3
  4. PHaroZ

    Jos Guest

    Server.MapPath(".")

    --

    Jos
    Jos, Nov 26, 2003
    #4
  5. PHaroZ

    sharmaravika

    Joined:
    Jun 15, 2012
    Messages:
    1
    This will give you the desired result

    Directory.GetParent(HttpContext.Current.Request.PhysicalPath).Parent.FullName
    sharmaravika, Jun 15, 2012
    #5
  6. PHaroZ

    akash02sap

    Joined:
    Aug 17, 2012
    Messages:
    1
    aspx code:-
    -----------------
    <form id="Form1" method="post" runat="server" >
    <div>

    <asp:FileUpload ID="FileUpload1" runat="server" />

    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <br />
    <asp:Label ID="lbl_path" runat="server"></asp:Label>
    <br />
    <asp:Label ID="path_lbl" runat="server"></asp:Label>

    </div>
    </form>

    aspx.vb code:-
    --------------------------
    Imports System.IO

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    lbl_path.Text = FileUpload1.PostedFile.FileName


    Dim path1 As String = "\" + lbl_path.Text

    Dim fullPath As String

    fullPath = Path.GetFullPath(FileUpload1.PostedFile.FileName)
    Console.WriteLine("GetFullPath('{0}') returns '{1}'", path1, fullPath)

    path_lbl.Text = Path.GetFullPath(FileUpload1.PostedFile.FileName)
    Console.WriteLine("GetFullPath('{0}') returns '{1}'", path1, fullPath)


    End Sub
    akash02sap, Aug 17, 2012
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Olav Tollefsen

    How to get directory path of current rquest?

    Olav Tollefsen, Oct 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,187
    Scott Mitchell [MVP]
    Oct 29, 2004
  2. xeroxero

    Get Current Full App Path?

    xeroxero, Dec 8, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    690
    Juan T. Llibre
    Dec 8, 2006
  3. Replies:
    26
    Views:
    988
    Lew Pitcher
    Jun 4, 2007
  4. dude
    Replies:
    5
    Views:
    1,675
    Jussi Piitulainen
    Mar 17, 2011
  5. Random Task
    Replies:
    2
    Views:
    95
Loading...

Share This Page