locked
../ or ~/ RRS feed

  • Question

  • User2062956768 posted

    friends

    when should I use

    ../folder name

    or 

    ~/folder name

    or

    file name directly

    Thank you

    Thursday, May 30, 2019 4:08 PM

All replies

  • User409696431 posted

    You use ~/folder name in a context that is processed on the server by asp.net, such as in asp.net controls.  It references the application root as ~ and describes the path from that root.

    You use '../folder name in the context of standard HTML, not server controls, where this example constructs a URL that is up one from the current folder, then down to the named folder,   In standard HTML you can also use "/folder" where "/" means the root of the site, which is generally also the root of the application.

    Thursday, May 30, 2019 9:12 PM
  • User-1174608757 posted

    Hi mrzoz,

    According to your description, you could see the details as below:

    1  '..' means one path level up (so if you're on /somefolder/index.aspx and you reference ../style.css then the latter would have to be in the parent folder of someFolder)

    2 '~/' means the root path of the current project is only valid on the server side.

    3 if you directly use file ,it means the current file in the same folder.

    Best Regards

    Wei

    Friday, May 31, 2019 1:50 AM
  • User1874411014 posted

    Hi mrzoz,

    ../folder name is used to access or go to the file or folder of the previous directory,

    It can be used as ../../folder name to go two levels up. This is used while using relative paths.

    You can refer this for more information on Path Reference:           https://www.javatpoint.com/html-file-path

    ~/folder name is used to resolve to the correct location, regardless of which folder it is called from.

    Likewise placing:

    <asp:Image ID="image1" runat="server" ImageUrl="~/images/img.jpg"/>

    on a page the framework will substitute the correct path to "images/img.jpg" where the folder "images" is present from the root.

    Monday, June 17, 2019 4:47 PM