I have a webform and I want to create a hyperlink to a text file, so that it opens on internet explorer in a new window. I have added the following
<a href="file:///D:/Test/Test.txt" id="hplTest" runat="server">testhyperlink</a>
Now when I click on the hyperlink, nothing is happening. No error. when I open a browser and type file:///D:/Test/Test.txt
, the file is opening.
I would appreciate if anybody could help me out.
You can not give physical path in href with file://
, give the url instead.
<a href="http://www.yourdomain.com/Test/Test.txt" id="hplTest" runat="server">testhyperlink</a>
If the file is within current site then use relative path.
<a href="~/Test/Test.txt" id="hplTest" runat="server">testhyperlink</a>
The ~ here is for root path.
The physical path is wrong in your example.
Either you can use absolute path
<a href="http://myDomain/folder/Test.txt" id="hplTest" runat="server">testhyperlink</a>
Or you can use the relative path
<a href="~/Test.txt" id="hplTest" runat="server">testhyperlink</a>
You can also use target
on anchor tag if you want to open it in a new window
<a href="~/Test.txt" id="hplTest" runat="server" target="_blank">testhyperlink</a>
More target Detail Link of MSDN
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.