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. Is there an opposite to Server.Mappath?

Is there an opposite to Server.Mappath?

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminquestion
2 Posts 2 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.
  • M Offline
    M Offline
    morphix
    wrote on last edited by
    #1

    Hi, i was coding a small wen util to manage files on a webserver, and i needed a function do get the url from a file with a absolute path. Ex file : "c:\inetpub\wwwroot\funnyWeb\bad.txt" wich translate to "/funnyweb/bad.txt" is there a function build in asp.net that does that?

    M 1 Reply Last reply
    0
    • M morphix

      Hi, i was coding a small wen util to manage files on a webserver, and i needed a function do get the url from a file with a absolute path. Ex file : "c:\inetpub\wwwroot\funnyWeb\bad.txt" wich translate to "/funnyweb/bad.txt" is there a function build in asp.net that does that?

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, From what I know, there is no public method like you say, however, you can write your own method. You first need to get the physical path of the application directory, then you can easily to convert a physical path to a virtual path. The sample code is something like this:

      private string MapVirtualPath(string physicalPath)
      {
      string baseDir = HttpRuntime.AppDomainAppPath;
      string virtualPath = "";
      if(physicalPath.IndexOf(baseDir) >= 0)
      {
      string text1 = physicalPath.Substring(baseDir.Length);
      text1 = text1.Replace("\\", "/");
      virtualPath = HttpRuntime.AppDomainAppVirtualPath + "/" + text1;
      }

      return virtualPath;
      }

      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