Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Invalid path for MapPath

Invalid path for MapPath

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasecomdesign
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J Dunlap
    wrote on last edited by
    #1

    I'm getting the exception "Invalid path for MapPath - A virtual path is expected" when trying to convert a path to a physical path using Server.MapPath(). This, I believe, is caused by the fact that I'm using an absolute path (like "http://www.fluiduitoolkit.com/design/assemblies/index.xml"), rather than a virtual path (like "design/assemblies/index.xml"). So I need to use a virtual path. All very well, but how does one convert an absolute path to a virtual path in ASP.NET? I haven't found a method that does this, nor have I found a property that gives me the application's web path (NOT physical path). Do you know how I could do this? Thanks in advance!

    "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
    "You must be the change you wish to see in the world." - Mahatma Gandhi

    S 1 Reply Last reply
    0
    • J J Dunlap

      I'm getting the exception "Invalid path for MapPath - A virtual path is expected" when trying to convert a path to a physical path using Server.MapPath(). This, I believe, is caused by the fact that I'm using an absolute path (like "http://www.fluiduitoolkit.com/design/assemblies/index.xml"), rather than a virtual path (like "design/assemblies/index.xml"). So I need to use a virtual path. All very well, but how does one convert an absolute path to a virtual path in ASP.NET? I haven't found a method that does this, nor have I found a property that gives me the application's web path (NOT physical path). Do you know how I could do this? Thanks in advance!

      "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
      "You must be the change you wish to see in the world." - Mahatma Gandhi

      S Offline
      S Offline
      Steve McLenithan
      wrote on last edited by
      #2

      Why not just create a mthod that strips out the domain part of the url leaving only the virtual path?

      // Steve McLenithan

      Family Guy: Season 2 - Episode 8

      J 1 Reply Last reply
      0
      • S Steve McLenithan

        Why not just create a mthod that strips out the domain part of the url leaving only the virtual path?

        // Steve McLenithan

        Family Guy: Season 2 - Episode 8

        J Offline
        J Offline
        J Dunlap
        wrote on last edited by
        #3

        Hmm... Well, I suppose you could take out everything before the first single "/" . See, I want the domain name to not be hard-coded.

        "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
        "You must be the change you wish to see in the world." - Mahatma Gandhi

        S 1 Reply Last reply
        0
        • J J Dunlap

          Hmm... Well, I suppose you could take out everything before the first single "/" . See, I want the domain name to not be hard-coded.

          "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
          "You must be the change you wish to see in the world." - Mahatma Gandhi

          S Offline
          S Offline
          Steve McLenithan
          wrote on last edited by
          #4

          jdunlap wrote: See, I want the domain name to not be hard-coded. Of course;)

          // Steve McLenithan

          Family Guy: Season 2 - Episode 8

          J 1 Reply Last reply
          0
          • S Steve McLenithan

            jdunlap wrote: See, I want the domain name to not be hard-coded. Of course;)

            // Steve McLenithan

            Family Guy: Season 2 - Episode 8

            J Offline
            J Offline
            J Dunlap
            wrote on last edited by
            #5

            How's this?

            public string AbsToVirtualPath(string spath)
            {
            int index=0;
            //most accurate method of checking for abs. path
            if(spath.IndexOf("://")==-1) return spath;
            //find the first "/" that's not double, and retrieve
            //what's beyond that
            while(index!=-1)
            {
            index=spath.IndexOf("/",index);
            if(index==-1) return spath;
            if(spath.Substring(index+1,1)=="/")
            {
            index+=2;
            }
            else
            {
            return spath.Substring(index+1,spath.Length-(index+1));
            }
            }
            }

            "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
            "You must be the change you wish to see in the world." - Mahatma Gandhi

            S 1 Reply Last reply
            0
            • J J Dunlap

              How's this?

              public string AbsToVirtualPath(string spath)
              {
              int index=0;
              //most accurate method of checking for abs. path
              if(spath.IndexOf("://")==-1) return spath;
              //find the first "/" that's not double, and retrieve
              //what's beyond that
              while(index!=-1)
              {
              index=spath.IndexOf("/",index);
              if(index==-1) return spath;
              if(spath.Substring(index+1,1)=="/")
              {
              index+=2;
              }
              else
              {
              return spath.Substring(index+1,spath.Length-(index+1));
              }
              }
              }

              "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
              "You must be the change you wish to see in the world." - Mahatma Gandhi

              S Offline
              S Offline
              Steve McLenithan
              wrote on last edited by
              #6

              Looks good to me.

              // Steve McLenithan

              Family Guy: Season 2 - Episode 8

              J 1 Reply Last reply
              0
              • S Steve McLenithan

                Looks good to me.

                // Steve McLenithan

                Family Guy: Season 2 - Episode 8

                J Offline
                J Offline
                J Dunlap
                wrote on last edited by
                #7

                Only problem is... The path: http://www.fluiduitoolkit/design/assemblies/index.xml becomes: http://www.fluiduitoolkit/design/**design/**assemblies/index.xml ...because it maps the path starting at /design instead of the root. Looks like this method won't work. I've gotta somehow get the path root, and strip that off.

                "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                "You must be the change you wish to see in the world." - Mahatma Gandhi

                J 1 Reply Last reply
                0
                • J J Dunlap

                  Only problem is... The path: http://www.fluiduitoolkit/design/assemblies/index.xml becomes: http://www.fluiduitoolkit/design/**design/**assemblies/index.xml ...because it maps the path starting at /design instead of the root. Looks like this method won't work. I've gotta somehow get the path root, and strip that off.

                  "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                  "You must be the change you wish to see in the world." - Mahatma Gandhi

                  J Offline
                  J Offline
                  jpribele
                  wrote on last edited by
                  #8

                  would Request.FilePath do what you want. It will return the virtual path of the given request. But if the path your trying use is not the currenct request that is a problem.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups