How to open a file by clicking on HyperLink

I have this table

enter image description here

I want to click the link and the file (any file) will be opened in a new popup.

Here is my code:

<asp:Repeater ID="dokumente" runat="server">
    <ItemTemplate>
        <tr>
            <td><asp:HyperLink ID="HyperLink4" runat="server" Text='<%# Eval("DokuTyp") %>' NavigateUrl='file://<%# Eval("File") %>'></asp:HyperLink></td>
            <td><%# Eval("Description")%></td>
            <td><%# Eval("Date") %></td>
            <td><%# Eval("File") %></td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

But this does not work with NavigateUrl. Can anyone help me on this or any idea how to do this. Thanks

+5
source share
3 answers

The file: /// is for resources on your own machine.

To open files on the server, you will need to link to the URLs on the server. Using:

HttpContext.Current.Request.ResolveUrl(pathOnServer);

Change your code as follows:

<asp:Repeater ID="dokumente" runat="server">
    <ItemTemplate>
        <tr>
            <td><asp:HyperLink ID="HyperLink4" runat="server" Text='<%# Eval("DokuTyp") %>' NavigateUrl='<%# HttpContext.Current.Request.ResolveUrl(Eval("File")) %>'></asp:HyperLink></td>
            <td><%# Eval("Description")%></td>
            <td><%# Eval("Date") %></td>
            <td><%# Eval("File") %></td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

Where is the server

+5
source

The file protocol opens a file on the user's computer. I think you should read the file on the server side and call Resposne.Write.

+1

, Server.MapPath; "file://" url,

NavigateUrl=<%#Server.MapPath(DataBinder.Eval("File"))%>
0

All Articles