Reputation: 446
I'm trying create a link to files located in local folder but it doesn't open the file. I'm using razor to create the links. My code is below:
<a href="@item.URL\@item.FileName" class="btn btn-info">@item.FileName </a>
and this what it outputs...
<a class="btn btn-info" href="C:\Users\Dev\Documents\sp\Create.txt">Create.txt </a>
but it doesn't open the file for some reason
Upvotes: 2
Views: 7019
Reputation: 1804
To call for a resource on your computer, you need to "tell" the browser it's a local path.
use:
<a href="file:///@item.URL\@item.FileName">
The file:///
(notice the three slashes) will indicate the location of the target.
Upvotes: 0
Reputation: 150208
The file does not open because the web server (fortunately, for security reasons) does not have access to the Dev user's Documents folder.
Use a relative path under the web application's root directory. App_Data is commonly used for that purpose, e.g.
<a href="@Url.Content("~/App_Data/sp/Create.txt")">Create.txt</a>
Upvotes: 5
Reputation: 731
This will work.
<a href="<%= Url.Content("~/sp/Create.txt") %>">Create.txt</a>
Upvotes: 0