Solved

How to open the pdf file appearing as hyperlink on click.

Posted on 2012-04-12
7
320 Views
Last Modified: 2012-04-13
I have the following code, which fethes the pdf files names searched for in a grid.
It file appears as hyperlink into the grid.
How to open that file. which ever is clickd.

<asp:TextBox ID="txtid" runat="server"></asp:TextBox>
        <asp:Button ID="btnsearch" runat="server" Text="Button" onclick="Button1_Click" />
       <asp:GridView ID="GridView1" runat ="server" CellPadding ="3" CellSpacing ="3" >
       <Columns>
          <asp:TemplateField HeaderText ="File">
    <ItemTemplate >

    <asp:HyperLink ID ="hyFile" runat="server" Text ='<%#Eval("Filename") %>' NavigateUrl ='<%#Eval("Filename") %>' ></asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateField>
</Columns>
</asp:GridView>

code behind

protected void btnsearch_Click(object sender, EventArgs e)
    {
        var lstFiles = Directory.GetFiles(MapPath("Files/"), string.Format("{0}_*.pdf".ToUpper(), txtid.Text), SearchOption.AllDirectories).Select(f => new { FileName = f.Substring(f.LastIndexOf('\\') + 1)}).ToList();
        GridView1.DataSource = lstFiles;
        GridView1.DataBind();
    }
0
Comment
Question by:searchsanjaysharma
  • 4
  • 3
7 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37841344
I don't understand your question.  If it is a PDF file with a '*.pdf' extension, then it should open in the browser when clicked if the Adobe Reader plugin is installed in your browser.  Otherwise, clicking on the link should ask if you want to download the file.
0
 

Author Comment

by:searchsanjaysharma
ID: 37841353
Its not happening. I m getting the hyperlink, but file is not getting opened or download.
*.pdf means the files are only of pdf files.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37841432
Please show me the hyperlink in the "View Source" of your browser.  I ask for that because that is what the browser sees, not your ASP code above.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:searchsanjaysharma
ID: 37841509
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
      Untitled Page
</title></head>
<body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTkwMDc5MTQ2MQ9kFgICAw9kFgICBQ88KwANAgAPFgQeC18hRGF0YUJvdW5kZx4LXyFJdGVtQ291bnQCAWQMFCsAARYIHgROYW1lBQhGaWxlTmFtZR4KSXNSZWFkT25seWgeBFR5cGUZKwIeCURhdGFGaWVsZAUIRmlsZU5hbWUWAmYPZBYEAgEPZBYEZg9kFgICAQ8PFgQeBFRleHQFIUFBQUFLNTM4OUZfRk9STTE2QV8yMDEyLTEzX1EyLnBkZh4LTmF2aWdhdGVVcmwFIUFBQUFLNTM4OUZfRk9STTE2QV8yMDEyLTEzX1EyLnBkZmRkAgEPDxYCHwYFIUFBQUFLNTM4OUZfRk9STTE2QV8yMDEyLTEzX1EyLnBkZmRkAgIPDxYCHgdWaXNpYmxlaGRkGAEFCUdyaWRWaWV3MQ88KwAKAQgCAWQDxOIp2cjX8Ovw3wYqo+v0jPZUEw==" />
</div>

<div>

      <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKzsq7zDALs0bLrBgKM54rGBiezstXwSj+EQ+txrINSYt7iN73v" />
</div>

    <div>
        <input name="TextBox1" type="text" value="AAAAK5389F" id="TextBox1" />
        <input type="submit" name="Button1" value="Button" id="Button1" />
       <div>
      <table cellspacing="3" cellpadding="3" rules="all" border="1" id="GridView1">
            <tr>
                  <th scope="col">File</th><th scope="col">FileName</th>
            </tr><tr>

                  <td>

    <a id="GridView1_ctl02_hyFile" href="AAAAK5389F_FORM16A_2012-13_Q2.pdf">AAAAK5389F_FORM16A_2012-13_Q2.pdf</a>
    </td><td>AAAAK5389F_FORM16A_2012-13_Q2.pdf</td>
            </tr>
      </table>
</div>
                 
    </div>
    </form>

</body>
</html>
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 37841555
If this file 'AAAAK5389F_FORM16A_2012-13_Q2.pdf' is in the same directory as the web page, then it should open or download.  If instead it is in another directory like "Files/", then the link needs to be href="Files/AAAAK5389F_FORM16A_2012-13_Q2.pdf".
0
 

Author Comment

by:searchsanjaysharma
ID: 37845654
How to put Files folder in hyperlink NavigatrURL
as Files/ does work there

<asp:HyperLink ID ="hyFile" runat="server" Text ='<%#Eval("Filename") %>' NavigateUrl ='<%#Eval("Filename") %>' ></asp:HyperLink>
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37845699
ok
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question