How can I get my /directory/ name?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bencoding
    New Member
    • Mar 2008
    • 21

    How can I get my /directory/ name?

    Hello, I am building a "Web App" in "Visual Web Developer 2005" and need to be able to read my directory, for example http://mywebapp.com/dirname/Default.aspx

    So how would I be able to read the current directory name which in this case is "dirname"
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    I'm not entirely sure what you mean by "read my directory."

    If you want to get the physical address of a relative path, you can use Server.MapPath( "relPath")

    If you need to read all the files in the directory or something like that, you can use the System.IO.Direc toryInfo object to do many things like that.

    Comment

    • bencoding
      New Member
      • Mar 2008
      • 21

      #3
      Ok, I can probably clarify that, ....I would like to get the directory or folder name so that I can use it in my code, for example if the directory name is /projects/Default.aspx

      I would write some code like

      if (directory name = 'projects')
      {
      // do something here
      }

      So I would like to be able to get the directory name to use in my code, and for testing purposes I am using Response.Write( ); to see if it works. I appreciate that code you gave me but is showing me too much data, I would just like the directory name.



      Originally posted by insertAlias
      I'm not entirely sure what you mean by "read my directory."

      If you want to get the physical address of a relative path, you can use Server.MapPath( "relPath")

      If you need to read all the files in the directory or something like that, you can use the System.IO.Direc toryInfo object to do many things like that.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Have you tried:
        Server.MapPath( ".") ?

        Comment

        • bencoding
          New Member
          • Mar 2008
          • 21

          #5
          I just tried Server.MapPath( ".") and it's closer to what I need, it gives me

          C:\Program Files\CCM\Proje cts

          ... I would need to extract "Projects" some how, if this is the closest I can get could I use a string function to strip everything out up to the 3rd "\" ?


          Originally posted by Plater
          Have you tried:
          Server.MapPath( ".") ?

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            Originally posted by bencoding
            I just tried Server.MapPath( ".") and it's closer to what I need, it gives me

            C:\Program Files\CCM\Proje cts

            ... I would need to extract "Projects" some how, if this is the closest I can get could I use a string function to strip everything out up to the 3rd "\" ?
            Use the .Split(delimite r) method.
            Code:
            //c# code, I don't know what language you use.
            string path = Server.MapPath(".");
            char[] delim = { '\\' };
            string[] tokens = path.Split(delim);
            string folder = tokens[tokens.Length-1];
            //now folder has "Projects"

            Comment

            • bencoding
              New Member
              • Mar 2008
              • 21

              #7
              thanks guys!.......... ..........

              Comment

              Working...