absolute path to url

  • Thread starter Thread starter Harrie Verveer
  • Start date Start date
H

Harrie Verveer

is there a way to convert an absolute path
(C:\inetpub\wwwroot\project\folder\another_folder\file.jpg) to an url?

I used this code:
---
string sk = Server.MapPath(".").ToLower();
url_to_use = filename.ToLower().Replace(sk,".").Replace("\\","/");
---

My problem now is that the file resides in another project folder on the
server (please don't ask why :P). The solution whould be to do something
like:

---
string sk = <path_of_wwwroot>
url_to_use = filename.ToLower().Replace(sk,"/").Replace("\\","/");
---

But I can't find a way to find the location of wwwroot - except for
MapPath(".."), which is not allowed :)

Anyone knows a solution?
 
if MapPath not allowed and the location is bound to future changes, one
method would be to keep a config key for this location..

you may have thought about this workaround already, in case u have not

<add key="another_folder" value="http://yoursite/yourroot/another_folder/"
/>


url_to_use = ConfigurationSettings.AppSettings["another_folder"] +
filename;

Sreejith
 
Back
Top