If you have the route in the BD and you have it in Data
, you should show a link with a blank target that points to the path of the file resulting in a file download by clicking on the link, see:
table.append("<tr id='row_" + i + "'><td style='display: none'>" + Data[i].id + "</td><td name='nombre'>" + Data[i].nombre "</td>" + "<td name='nomArchivo'>" + "<a href='http://AquiVaTuDominio.com/'" + Data[i].ruta + " target='_blank'>" + Data[i].nomArchivo + "</a></td></td></tr>");
Update
Now knowing in detail the characteristics of how the software is being built, here is a better answer:
First we create a Generic Handler (* .ashx) called FileCS
in the root of the project with the following code:
<%@ WebHandler Language="C#" Class="FileCS" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class FileCS : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//Aqui falta algo importante: saber si el usuario está autenticado para darle la seguridad del caso
int id = int.Parse(context.Request.QueryString["IdDeMiPDF"]);
byte[] bytesDelPDF;
string fileName, contentType;
//De aqui sacamos la cadena de conexion
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT nombre, ruta, tipo FROM nombreDeLaTabla WHERE Id=@IdDeMiPDF";
cmd.Parameters.AddWithValue("@IdDeMiPDF", id);
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
bytesDelPDF = (byte[])sdr["ruta"];
contentType = sdr["tipo"].ToString();
fileName = sdr["nombre"].ToString();
}
con.Close();
}
}
context.Response.Buffer = true;
context.Response.Charset = "";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.ContentType = "application/pdf";
context.Response.BinaryWrite(bytesDelPDF);
context.Response.Flush();
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
Second, define the call to that file by sending the ID
ResolveUrl("~/FileCS.ashx?IdDeMiPDF=") //Y le agregas el ID, esto corre en el lado del servidor, tienes que ver cual es la ruta del archivo y lo llamas.
In your javascript
the idea goes like this:
Change this
"<a href='http://AquiVaTuDominio.com/'" + Data[i].ruta + "target='_blank'>"
For something similar:
"<a href='http://AquiVaTuDominio.com/FileCS.ashx?IdDeMiPDF='" + Data[i].id+ "target='_blank'>"
Note where the FileCS.ashx
file is.
Reference: link