Solved

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

Posted on 2012-04-12
7
317 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 82

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 82

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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 82

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

20 Experts available now in Live!

Get 1:1 Help Now