Private void getfiledata (string file_code)
{
Datatable dt = L. getfiledata (file_code );
If (DT! = NULL & DT. Rows. Count> 0)
{
String type = DT. Rows [0] ["content_type"]. tostring ();
Byte [] b2 = (byte []) dt. Rows [0] ["file_data"];
Long Len = convert. toint64 (Dt. Rows [0] ["file_length"]);
Response. Clear ();
Response. addheader ("content-disposition", "attachment; filename =" + datetime. now. tostring ("yyyy-mm-dd-hhmmssfff") + dt. rows [0] ["file_ext"]. tostring ());
Response. addheader ("Content-Length", Len. tostring ());
Response. contenttype = type;
Response. binarywrite (B2 );
Response. End ();
}
}
Database storage content: contenttype, extension, binary data.
Convert a text file to binary:
Private byte [] changefiletobyte (string filename)
{
Filestream FS = file. openread (filename );
Byte [] fbyte = new byte [fs. Length];
FS. Read (fbyte, 0, fbyte. Length );
FS. Close ();
Return fbyte;
}