2

The following code:

Dim url       
url = fso.GetAbsolutePathName(objFile)

gives me

C:\KB\Dev\Java.htm

Then, when I write it as an href:

Response.Write("<a href='" + url + "'>" + objFile.Name + "</a><br>")

the link is translated in browser into:

file:///C:/KB/Dev/Java/Java.htm

whereas I will need it to be

file://172.20.4.107/c$/KB/Dev/Java/Java.htm

or else, the link won't be valid for navigation.

I was trying:

url = Replace(url, "///", "//172.20.4.107/")
url = Replace(url, "c:", "c$")
Response.Write(url & "<br>")

but nothing seems to be changed.

user692942
  • 14,779
  • 6
  • 66
  • 157
dushkin
  • 1,541
  • 1
  • 19
  • 48

2 Answers2

2

You're trying to replace /// but these characters are not in your url variable. url is C:\KB\Dev\Java.htm.

Try this instead:

url = Replace(url, "\", "/")
url = Replace(url, "C:/", "file://172.20.4.107/c$/")

Also keep in mind that it is the end user's browser that is converting your C:\... path to the file://... format. That is not happening in your ASP code.

Keith
  • 18,957
  • 10
  • 75
  • 119
  • This is it! But how come now, when the link seems to be correct, it is not going to this address when I click on it ? :( And even when I try to "open it in a new tab" I get an "about:blank" page... – dushkin Feb 29 '16 at 14:04
  • It could be a permissions issue, most likely on the c$ share. – Keith Feb 29 '16 at 14:12
  • 1
    @dushkin Because browsers see accessing network file shares through hyperlinks as a security risk. i.e - http://stackoverflow.com/questions/811570/how-do-i-make-a-file-hyperlink-that-works-in-both-ie-and-firefox Also this might be helpful - [What are the ways to make an html link open a folder](http://stackoverflow.com/q/855614/692942) – user692942 Feb 29 '16 at 14:12
  • @Lankymart Strange... because if I copy the shortcut of the link and paste it in the address bar - it opens without any problems. Is there a way to overcome this? I will go over your links too... – dushkin Feb 29 '16 at 14:17
  • @dushkin Not strange if you think about it, no one has control of your URL address bar but hyper-links in a page can come from anywhere. Personally I would assess why you need to access it using this method, could you not map it to the web server then expose it via a virtual directory in IIS for example? – user692942 Feb 29 '16 at 14:19
  • @Lankymart That is bacause I am totally new to web programming... :-) If you could send me such a tutorial it would be great! – dushkin Feb 29 '16 at 14:28
  • 1
    @dushkin [How to create a virtual directory on an existing Web site to a folder that resides on a remote computer](https://support.microsoft.com/en-us/kb/308150) – user692942 Feb 29 '16 at 14:30
2

What @Keith suggested is absolutely fine but you will encounter issue with various degrees in most modern browsers due to hyper linking from local file links being blocked as they're a security risk.

A more robust solution is to not use local file links and negate the risk completely. If you have access to IIS (If you are using Classic ASP you likely have access to IIS in some form) you can do this by creating a Virtual Directory that points to your remote computer share and lock down the permissions as you see fit.

Say you set-up a Virtual Directory to point to alias KB you could then access it;

http://yourhost/KB/dev/java.htm

If the Virtual Directory was mapped to

\\172.20.4.107\c$\KB\

However we can take it a stage further, Admin Shares such as c$ are not configurable and there for the system to use. To have better control over the mapped directory create a share KB for example on the remote computer and set the NTFS permissions as appropriate then point the Virtual Directory to;

\\172.20.4.107\KB\

You can also call the share KB$ to hide the share from network browsers.

\\172.20.4.107\KB$\

Useful Links

Community
  • 1
  • 1
user692942
  • 14,779
  • 6
  • 66
  • 157