Solved

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

Posted on 2012-04-12
7
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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