Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reverse server.mappath 1

Status
Not open for further replies.

EddieVenus

Technical User
Apr 8, 2002
176
US
Is there a command that does this? I need to take a variable 'objF' that is given the actual path to a file. I then need to convert this to the virtual path, which is already set up in IIS so it should be there. Maybe i am going about this the long way, but since I used server.mappath to go from virtual to actual, I wanted to see if there was a way to go from actual to virtual to make the URLs work.

What I am trying to do, is make a directory listing with links to said files.
 
So you are trying to change "/" to "\" ? or the other way around.. if I understand you right just use the replace function

MyString = Replace(MyDir, "/", "\")

Response.Write MyString www.vzio.com
ASP WEB DEVELOPMENT



 
although that is a handy tool now, and I used it someplace else now that I know about it, it is not exactly what I am looking for. And I am afraid if you , snowboardr, do not know it then perhaps no-one does. What I need is to get "F:\Shared\Final" out of "files/". "F:\shared\final" bing the physical dir, and "final/" being the virtual representation of it in IIS. I can put in server.mappath("files/") and get "F:\shared\final", but I want to do it in reverse. I.e. ReverseSever.mappath("F:\shared\final") and have it translate that to "files/". Is this possible?
 
I wanted you to know that I have just recoded that page, so I do not need this information anymore, but it is still interesting. So if anyone knows how, please post it, as it might help someone sometime. I know I could use it.
 
I am not sure I understand what you are trying to do. www.vzio.com
ASP WEB DEVELOPMENT



 
I'm at a loss also. why would you need to get a path out of something like files/
I suppose if you do however snow showed you how. just save the value of the path in a var and use the replace with the other on the condition of whatever you get out of the current value
something like
dim var1, var2
var1 = "files/"
var2 = "F:\shared\final"
if var1 = "files/" then
var1 = Replace(var1, var1, var2)
else
something....
end if
Hope that helps,
Ted
admin@onpntwebdesigns.com
 
I can't exactly see the reason it is needed by I do understand the problem. Just doing a reversing of the slashes will not work.
Basically he use looking for a reverse mapping to a virtual directory from a statis directory. Interesting problem.

If you only need the virtual path from the page that is being called, than you can use Request.ServerVariables("PATH_INFO") to get it. However, I think in your case you have a physical path and wish to convert it to a virtual path before directing a user there.

Here is one solution. Create an array that will map virtual root directories to their physical counterparts.
In our sample case we will have three directories:/, /samples, and /other
The physical directories will be:
C:\Inetpub\ (assume a shared drive)

Code:
<%
Function ReverseMap(path)
   Dim mapArray(3,1)
   mapArray(0,0) = &quot;/samples&quot;
   mapArray(0,1) = &quot;C:\myotherwebpage\samples\&quot;
   mapArray(1,0) = &quot;/other&quot;
   mapArray(1,1) = &quot;X:\intranetpages\securedpages\&quot;
   mapArray(2,0) = &quot;/books&quot;
   mapArray(2,1) = &quot;C:\Inetpub\[URL unfurl="true"]wwwroot\homepage\books\&quot;[/URL]
   mapArray(3,0) = &quot;&quot;
   mapArray(3,1) = &quot;C:\Inetpub\[URL unfurl="true"]wwwroot\&quot;[/URL]

   Dim check, i
   i = 0
   Do While check = false AND i <= UBound(mapArray)
      If InStr(path,mapArray(i,1)) Then
         ReverseMap = mapArray(i,0) & &quot;/&quot; & Replace(right(path,(len(path) - len(mapArray(i,1)))),&quot;\&quot;,&quot;/&quot;)
         check = true
      End If
	  i = i + 1
   Loop
   
   If check = false Then ReverseMap = &quot;No Path Found&quot;
End Function

Response.Write ReverseMap(&quot;X:\intranetpages\securedpages\test.asp&quot;) & &quot;<BR>&quot;
Response.Write ReverseMap(&quot;C:\myotherwebpage\samples\library\overduebooks.html&quot;) & &quot;<BR>&quot;
Response.Write ReverseMap(&quot;C:\Inetpub\[URL unfurl="true"]wwwroot\homepage\books\mybooks.asp&quot;)[/URL] & &quot;<BR>&quot;
Response.Write ReverseMap(&quot;C:\Inetpub\[URL unfurl="true"]wwwroot\newhomepage\books\mybooks.asp&quot;)[/URL] & &quot;<BR>&quot;
%>

Included are four test function calls to show the use of the function.

This is kind of unwieldy as you actually have to specify the address mapping yourself, but as the mapping probably won't change often, this should be at most a once a month update, if ever.
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Tarwn, that was fantastic. You hit the nail on the head when you saw what I was trying to do. Sometimes I have a hard time explaining things, but this approach is near perfect. Like you said it is way to big to use alot, but in my case this issue is a one time thing, so size is of no concern. Thank you for your insight. I will attempt to impliment this when I get back to that page. Since then I have stumbled on other pages with other problems, so you may never know if this works for me, but I can take the idea and run with it, so thank you.
 
I noticed you put in X: as a shared drive. That is my latest stumbling block, how do you make a shared drive work. All I ever get is path not found errors. Is there something I need to do, maybe a problem with IIS? The drive is successfully mapped in WinExplorer, but not in IIS. I just get the error stop sign icon by the drive name, and when I try to use it I get the above mentioned errors. I know this is off the subject, I just thought maybe someone could shed some light on it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top