// Download an object
String connstr = system. configuration. configurationsettings. etettings ["connectionstring"];
String str_get_file = "select * From fmfilecont where fileid = 9 ";
Sqlconnection conn = new sqlconnection (connstr );
Sqlcommand mycommand = new sqlcommand (str_get_file, Conn );
Conn. open ();
Sqldatareader DR = mycommand. executereader ();
If (dr. Read ())
{String filename = Dr ["fname"]. tostring ();
Response. Buffer = true;
Response. Clear ();
Response. contenttype = "+ Dr [FTYPE] +"; // Read File Type
Page. response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (filename ));
// When the file name to be downloaded is Chinese, add httputility. urlencode
Byte [] file = (byte []) Dr ["Cont"];
// Fields of files stored in the database. The data type is image.
Response. binarywrite (File );
Response. Flush ();
Response. End ();
// Open a file directly
Int id = convert. toint32 (request. querystring ["docid"], 10 );
String connstr = system. configuration. configurationsettings. etettings ["connectionstring"];
String str_get_file = "select * From fmfilecont where fileid =" + ID;
Sqlconnection conn = new sqlconnection (connstr );
Sqlcommand mycommand = new sqlcommand (str_get_file, Conn );
Conn. open ();
Sqldatareader DR = mycommand. executereader ();
If (dr. Read ())
{
Response. contenttype = (string) Dr ["FTYPE"];
Response. outputstream. Write (byte []) Dr ["Cont"], 0, (INT) Dr ["size"]);
}
Else
{
Response. Write ("this file is not available ");
Response. End ();
}
Dr. Close ();
Mycommand. Connection. Close ();