title: Gridview with download and view pdf files in asp.net & c#
body: <p>Everything is working fine, until the pdf file should be able to be clicked n viewd on the browser.Though the download link is working perfectly.</p>
  
  <p>My grid...</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" EmptyDataText = "No files uploaded"&gt;
  &lt;Columns&gt;
      &lt;asp:BoundField DataField="FileDate" HeaderText="Dated" /&gt;
      &lt;asp:BoundField DataField="FileName" HeaderText="File Name" /&gt;
      &lt;asp:TemplateField&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:LinkButton ID="lnkDownload" Text="Download" CommandArgument='&lt;%#   Eval("FilePath") %&gt;' runat="server" OnClick = "DownloadFile" &gt;&lt;/asp:LinkButton&gt;
               &lt;asp:LinkButton ID="btnOpen" Text="View" Font-Bold="true" runat="server" onclick="btnpdf_Click" /&gt;&lt;/asp:LinkButton&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>My class</p>
  
  <pre><code>public class Thing
  {
  
      public string FilePath { get; set; }
      public string FileName { get; set; }
      public string FileDate { get; set; }
  }
  </code></pre>
  
  <p>My PageLoad</p>
  
  <pre><code> string[] filePaths = Directory.GetFiles(Server.MapPath("~/Uploads/"));
          List&lt;Thing&gt; lst = new List&lt;Thing&gt;();
          foreach (string filePath in filePaths)
          {
              lst.Add(new Thing() 
              { 
  
                  //FileDate = File.GetCreationTime(filePath).ToShortDateString(),
                  FileDate = Path.GetFileName(filePath.Substring(0,35)),
                  FileName = Path.GetFileName(filePath.Substring(36)), 
                  FilePath = filePath 
              });
          }
          GridView1.DataSource = lst;
          GridView1.DataBind();
  </code></pre>
  
  <p>My download button</p>
  
  <pre><code>string filePath = (sender as LinkButton).CommandArgument;
      Response.ContentType = ContentType;
      Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath.Substring(36)));
      Response.WriteFile(filePath);
      Response.End();
  </code></pre>
  
  <p>My pdfview</p>
  
  <pre><code>string filePath = (sender as LinkButton).CommandArgument;
      Response.ContentType = "Application/pdf";
      //Get the physical path to the file.
      Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath.Substring(36)));
      //Write the file directly to the HTTP content output stream.
      Response.WriteFile(filePath);
      Response.End();
  </code></pre>
  
  <p>Still i cannot view the pdf on a browser...pls help</p>