将Oracle数据库中HR方案下的TESTFILEUPLOAD表中的文件下载至系统临时目录。
void downloadFile()
??{
???OracleConnection objOcon = new OracleConnection("user id=system;Data Source=tsems;password=system");
???OracleCommand objOcmd = new OracleCommand();
???objOcmd.Connection = objOcon;
???objOcmd.CommandText = "SELECT * FROM HR.TESTFILEUPLOAD WHERE PKID='2006'";
???FileStream objFs;
???BinaryWriter objBw;
???int bufferSize = 260;
???byte [] outByte = new byte[bufferSize];
???long retval;
???long startIndex = 0;
???string fileName = "";
???objOcon.Open();
???OracleDataReader objDr = objOcmd.ExecuteReader(CommandBehavior.SequentialAccess);
???objDr.Read();
?? fileName = objDr["FILENAME"].ToString();
???objFs = new FileStream(Path.GetTempPath()+fileName, FileMode.OpenOrCreate,FileAccess.Write);
???objBw = new BinaryWriter(objFs);
???startIndex = 0;
???retval = objDr.GetBytes(8, startIndex, outByte, 0, bufferSize);
???while ( retval == bufferSize)
???{
????objBw.Write(outByte);
????objBw.Flush();
????startIndex += bufferSize;
????retval = objDr.GetBytes(8, startIndex, outByte, 0, bufferSize);
???}
???objBw.Write(outByte, 0, (int)retval -1);
???objBw.Flush();
???objBw.Close();
???objFs.Close();
?? bjDr.Close();
???objOcon.Close();
??}