Solved

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

Posted on 2012-04-12
7
318 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now