Question

Is there a way to open a PDF file from a remote server directory inside a gridview using NavigateUrl? I'm able to retrieve the file number from the textbox and generate the link, but when you click on the link nothing happens. Could my NavigateUrl be formatted wrong due it being on a remote server and trying to open in a web browser? My code below. Thanks in advance.

            <asp:TemplateField>
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" runat="server" 
                        NavigateUrl='<%# Eval("Name", "file:\\fileserver\pdf\{0}") %>' 
                        Target="_blank" Text='<%# Eval("Name", "{0:d}") %>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Name" DataFormatString="{0:d}" HeaderText="FILE NUMBER" />
            <asp:BoundField DataField="CreationTime" DataFormatString="{0:d}" HeaderText="DATE ADDED" />
            <asp:BoundField DataField="Length" DataFormatString="{0:#,### bytes}" HeaderText="FILE SIZE" />
Was it helpful?

Solution 2

You will need to have the file accessible via http:// and not file:// in order for the the link to work properly.

Once that is set, use the Server.MapPath() method to generate the URL based on the path to your file.

OTHER TIPS

The navigate url needs to look like a URL not a physical file path. somthing like http://server/path/x.pdf. If you own the share where the documents are stored consider adding a virtual directory that points at the remote server and directory. After that it would be possible to access the files from your asp.net application by using http://yourserver/virtualpath/x.pdf

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top