So I'm working on an Intranet web application using ASP.NET MVC, and I need to create a link to a folder on the network. So, as an example, let's say I wanted to create a link to "C:\", and this uri is stored in site.DocsPath
. I figured the easiest way to do this was just create a regular link, like this:
<a href="file:///<%= site.DocsPath %>">Documents</a>
This resolves to:
<a href="file:///C:\ruby">Documents</a>
However, when you click on the link, nothing happens. It's basically like clicking on regular text; absolutely nothing happens. No redirection, nothing. I tried this in both Firefox and IE, and this same behavior happens in both.
Initially I thought it might be the slashes. So I pasted file:///C:\ruby
into the address bar, to see if it was even right. It worked. I tried this in both Firefox and IE, and it works in both.
So now, I'm thinking "hey, maybe my html isn't proper for some reason". So I created a small html page, as such:
<html>
<head><title>Test Page</title></head>
<body>
<a href="file:///C:\ruby">Documents</a>
</body>
</html>
And lo and behold..... it worked. I click on the link, and it actually follows the link. And this works in both Firefox and IE.
So now I'm confused. The HTML is exactly the same in both cases (through ASP.NET MVC and in static HTML). And yet it only works in the static HTML case.
Now, I'm just pulling at straws. I try just pasting
<a href="file:///C:\ruby">Documents</a>
straight into the ViewPage in ASP.NET MVC. Nope, doesn't work.
Then I try pasting just a random website statically into the ViewPage, like:
<a href="http://www.google.com">Supreme Overlord of the Internet</a>
And that works. So, now I have confirmed that ASP.NET actually can follow hand-generated links.
Now, with just nothing left to do, I do something crazy. I set the link to somewhere that doesn't exist, like:
<a href="file:///X:\this\doesnt\exist">I Hate ASP.NET MVC right now</a>
Firefox sticks to its guns and doesn't follow it. However, IE actually follows it and gives me an error page. The same thing happens if site.DocsPath = "X:\this\doesnt\exist"
and I put:
<a href="file:///<%= site.DocsPath %>">Documents</a>
So now, I'm totally confused. I don't know what the heck is going on. Clearly, ASP.NET MVC hates me, which is troubling because I have shown it nothing but love.
If anyone has any idea what is going on, I would greatly appreciate the help. Thanks!
UPDATE: After much testing (and many very helpful answers and comments from everyone here at SO), I've come to the conclusion that just creating a normal link to the folder just will not work. I eventually tried putting that static html page I created above on a webserver, and it turns out that it doesn't work. I also created a Ruby on Rails application and a small PHP application and tried it through those, and it doesn't work on them either. So the only other possibility is that it is in fact a browser thing.
I think I will pursue maybe somehow connecting to the SharePoint server that all the documents are managed by. Thanks to everyone who commented and provided various answers on the question. I can only pick one answer, but everyone's comments and answers really provided a clear picture as to what was going on. Thanks!