Ragnarsson
Ragnarsson

Reputation: 1825

How to open a file by clicking on HyperLink

I have this table

enter image description here

I want to click on the link and the file (whatever file) will be opened in a new pop-up window.

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 it doesn't work with NavigateUrl. Can anyone help me on this or any idea how to do this. Thanks

Upvotes: 5

Views: 19774

Answers (3)

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

If you want find file on server you can use Server.MapPath method; "file://" is not correct url if you want find file on server

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

Upvotes: 0

nunespascal
nunespascal

Reputation: 17724

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

To open files on a server, you will have to link to urls on the server. Use:

HttpContext.Current.Request.ResolveUrl(pathOnServer);

Change your code like this:

<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 Server

Upvotes: 5

The "file" protocol opens a file in the user computer. I guess you have to read the file on the server-side and call a Resposne.Write.

Upvotes: 1

Related Questions