Solved

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

Posted on 2012-04-12
7
323 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 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