This is to read the saved files from the database and write them to the client, and the files are not directly opened in the client browser.
String s_conn = configurationsettings. receivettings ["dbconnisms"];
Sqlconnection conn = new sqlconnection (s_conn );
String ssql = "select certificate, cert_size, cert_format from t_accept_certificate" +
"Where seq_no =" + sseqno;
Sqlcommand comm = new sqlcommand (ssql, Conn );
Conn. open ();
Sqldatareader reader = comm. executereader ();
While (reader. Read ())
{
Sqlbinary buffer = reader. getsqlbinary (0 );
String format = reader ["cert_format"]. tostring ();
String filename = "";
Switch (Format)
{
Case "1 ":
{
Filename = "certificate.doc ";
Break;
}
Case "2 ":
{
Filename = "certificate.xls ";
Break;
}
Case "3 ":
{
Filename = "certificate.pdf ";
Break;
}
}
String certsize = reader ["cert_size"]. tostring ();
Response. Clear ();
Response. clearcontent ();
Response. clearheaders ();
Response. contenttype = "application/octet-stream ";
Response. addheader ("content-disposition", "attachment; filename =" + filename );
Response. addheader ("Content-Length", certsize );
If (! Buffer. isnull)
Response. binarywrite (buffer. value );
response. End ();
}