简体   繁体   中英

How create a link to open local file?

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

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, eg

<a href="@Url.Content("~/App_Data/sp/Create.txt")">Create.txt</a>

这将起作用。

<a href="<%= Url.Content("~/sp/Create.txt") %>">Create.txt</a>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM