System.Data.OleDb.OleDbConnection conn = null;
System.Data.OleDb.OleDbCommand cmd = null;
System.Data.OleDb.OleDbDataReader reader = null;
System.IO.FileStream fileStream = null;
System.IO.BinaryWriter writer = null;
int bufferSize = 1000;
byte[] buffer = new byte[bufferSize];
long startIndex = 0;
long numberOfBytes = 0;
conn = new System.Data.OleDb.OleDbConnection("Provider" +
"=Microsoft.Jet.OLEDB.4.0;Data Source=" + AccessFile.Text);
cmd = new System.Data.OleDb.OleDbCommand("SELECT [File] " +
"FROM [File] WHERE [FileName] = '" +
FileListView.SelectedItems[0].Text + "'", conn);
conn.Open();
reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
reader.Read();
fileStream = new System.IO.FileStream(DataFile.Text,
System.IO.FileMode.OpenOrCreate,
System.IO.FileAccess.Write);
writer = new System.IO.BinaryWriter(fileStream);
do {
numberOfBytes = reader.GetBytes(0,
startIndex, buffer, 0, bufferSize);
if(numberOfBytes == 0) {
break;
}
writer.Write(buffer, 0, (int) numberOfBytes);
startIndex += numberOfBytes;
} while (true);
writer.Flush();