Private void download (string ID)
{
String filename = page. Request. physicalapplicationpath + "systemmanage \ sysfile \" + datetime. Now. tostring ("yyyymmddhhmmss") + ". Zip ";
Oracleconnection conn = NULL;
String connstring = system. configuration. configurationsettings. etettings ["connectionstring"]. tostring ();
Using (conn = new oracleconnection (connstring ))
{
Try
{
Conn. open ();
Oraclecommand cmd = conn. createcommand ();
// Use transaction processing (required)
Oracletransaction transaction = cmd. Connection. begintransaction ();
Cmd. Transaction = transaction;
// Obtain the Blob information of the uploaded file based on the query statement.
String SQL = "Select Upload file from File Upload table where no. =" + ID;
Cmd. commandtext = SQL;
Oracledatareader DR = cmd. executereader ();
Dr. Read ();
Required lelob templob = dr. get1_lelob (0 );
Dr. Close ();
// Read BLOB data and write it to the file
Filestream FS = new filestream (filename, filemode. Create );
Int length = 1048576;
Byte [] buffer = new byte [length];
Int I;
While (I = templob. Read (buffer, 0, length)> 0)
{
FS. Write (buffer, 0, I );
}
FS. Close ();
Templob. Clone ();
Cmd. Parameters. Clear ();
// Submit the transaction
Transaction. Commit ();
Downloadfile (filename );
File. Delete (filename );
}
Catch (exception ex)
{
Throw ex;
}
Finally
{
Conn. Close ();
}
}
}
/// <Summary>
/// Download an object
/// </Summary>
/// <Param name = "FILENAME"> file name </param>
Public void downloadfile (string filename)
{
Try
{
// By K 2010-08-13 use the following method to download attachments larger than MB
System. Io. Stream istream = NULL;
// Buffer to read 10 K bytes in Chunk:
Byte [] buffer = new byte [10000];
// Length of the file:
Int length;
// Total Bytes to read:
Long datatoread;
// Identify the file to download including its path.
String filepath = filename;
// Identify the file name.
String filename = system. Io. Path. getfilename (filepath );
Try
{
// Open the file.
Istream = new system. Io. filestream (filepath, system. Io. filemode. Open,
System. Io. fileaccess. Read, system. Io. fileshare. Read );
// Total Bytes to read:
Datatoread = istream. length;
Response. contenttype = "application/octet-stream ";
Response. addheader ("content-disposition", "attachment; filename =" + filename );
// Read the bytes.
While (datatoread> 0)
{
// Verify that the client is connected.
If (response. isclientconnected)
{
// Read the data in buffer.
Length = istream. Read (buffer, 0, 10000 );
// Write the data to the current output stream.
Response. outputstream. Write (buffer, 0, length );
// Flush the data to the HTML output.
Response. Flush ();
Buffer = new byte [10000];
Datatoread = datatoread-length;
}
Else
{
// Prevent infinite loop if user disconnects
Datatoread =-1;
}
}
}
Catch (exception ex)
{
// Trap the error, if any.
Response. Write ("error:" + ex. Message );
}
Finally
{
If (istream! = NULL)
{
// Close the file.
Istream. Close ();
}
}
}
Catch (exception ex)
{
Appcode. commonfunc. alertscript ("sorry, an error occurred while downloading the file! ");
}
}