dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleBFile Class
Members Example

In This Topic
    OracleBFile Class
    In This Topic
    Represents a managed OracleBFile object to work with the Oracle BFILE data type.
    Syntax
    'Declaration
     
    Public NotInheritable Class OracleBFile 
       Inherits OracleLob
       Implements System.Data.SqlTypes.INullableSystem.ICloneableSystem.IComparableSystem.IDisposable 
    Remarks
    The Oracle BFILE data type represents a reference to the physical file in the operating system where Oracle is installed. Maximum size of the file is 4 gigabytes. The OracleDbType.BFile data type cannot be modified and provides read-only access to data. So write-oriented methods of OracleBFile class are not supported.

    To read data use Read and OracleLob.Seek methods.

    Example

    The following sample shows how the OracleBFile class can be used. We insert a BFile object to the database and then print the content of the corresponding file on the physical drive. To run the sample, you need to create the BFileTable table first:

    CREATE TABLE BFileTable (
      id NUMBER,
      bf BFILE)
    
    // 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();
    }
    ' Open a connection
    Dim con = New OracleConnection("Server = Ora; User Id = Scott; Password = tiger;")
    con.Open()
    
    Dim 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.
    Dim bFile As OracleBFile = 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"
    Dim reader = com.ExecuteReader()
    
    While reader.Read()
    
        ' Get BFiles from the reader and print a part of their content.
        bFile = reader.GetOracleBFile(1)
        bFile.OpenFile()
    
        Dim buffer As Byte() = New Byte(100) {}
        bFile.Read(buffer, 0, 100)
        For Each bt As Byte In buffer
            Console.Write(bt & " ")
        Next
    
        Console.WriteLine()
    
        bFile.Close()
    
    End While
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.IO.Stream
             Devart.Data.Oracle.OracleLob
                Devart.Data.Oracle.OracleBFile

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also