protected void ddComapanyFilter_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlLabTest = (DropDownList)sender;
DataGridItem row = (DataGridItem)ddlLabTest.NamingContainer;
DropDownList ddlAddLabTestShortName = (DropDownList)row.FindControl("ddlCountries");
string sql = "select Data from RetPDF where Data = '" + ddlAddLabTestShortName.SelectedValue + "'";
string conString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand(sql);
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
cmd = new SqlCommand(sql, con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
byte[] lesson = (byte[])(dr[0]);
String spathfile = System.IO.Path.GetTempFileName();
//move from soures to destination the extension until now is .temp
System.IO.File.Move(spathfile,
System.IO.Path.ChangeExtension(spathfile, ".pdf"));
//make it real pdf file extension .pdf
spathfile = System.IO.Path.ChangeExtension(spathfile, ".pdf");
System.IO.File.WriteAllBytes(spathfile, lesson);
ddlAddLabTestShortName.Items.Insert(0, new ListItem("Please Select PDF Files", ""));
FileStream MyFileStream;
long FileSize;
MyFileStream = new FileStream(spathfile, FileMode.Open);
FileSize = MyFileStream.Length;
byte[] Buffer = new byte[(int)FileSize];
MyFileStream.Read(Buffer, 0, (int)FileSize);
MyFileStream.Close();
Response.ContentType = "application/pdf";
Response.Write("<b>File Contents: </b>");
Response.BinaryWrite(Buffer);
Response.Flush();
Response.End();
con.Close();
}
}
}