// Open a connection
OracleConnection con = new OracleConnection("Server = Ora; User Id = Scott; Password = tiger;");
con.Open();
OracleCommand com = new OracleCommand();
com.Connection = con;
// Create an Oracle directory corresponding to the folder containing the file.
com.CommandText = "CREATE OR REPLACE DIRECTORY Images as 'D:\\images\\'";
com.ExecuteNonQuery();
// Create an OracleBFile object.
// Note that the directory name should be in upper case.
// Otherwise, it will be case-sensitive and may cause errors.
OracleBFile bFile = new OracleBFile(con, "IMAGES", "image001.jpg");
// Insert the OracleBFile object to the database.
com.CommandText = "INSERT INTO BFileTable VALUES (1, :bfile)";
com.Parameters.Add(new OracleParameter("bfile", bFile));
com.ExecuteNonQuery();
// Retrieve data from the table.
com.Parameters.Clear();
com.CommandText = "SELECT * FROM BFileTable";
OracleDataReader reader = com.ExecuteReader();
while (reader.Read()) {
// Get BFiles from the reader and print a part of their content.
bFile = reader.GetOracleBFile(1);
bFile.OpenFile();
byte[] buffer = new byte[100];
bFile.Read(buffer, 0, 100);
foreach(byte bt in buffer)
Console.Write(bt + " ");
Console.WriteLine();
bFile.Close();
}