Esempio n. 1
0
        // <Snippet1>
        private void GetOracleBFile(string connectionString)
        {
            //Create and open the connection.
            using (OracleConnection connection = new OracleConnection(connectionString))
            {
                connection.Open();

                //Create and execute the commands.
                OracleCommand command = connection.CreateCommand();
                command.CommandText = "CREATE OR REPLACE DIRECTORY TestDir AS 'c:\\bfiles'";
                command.ExecuteNonQuery();
                command.CommandText = "CREATE TABLE TestTable(col1 number, col2 BFILE)";
                command.ExecuteNonQuery();
                command.CommandText = "INSERT INTO TestTable VALUES ('2', BFILENAME('TESTDIR', 'File.jpg'))";
                command.ExecuteNonQuery();
                command.CommandText = "SELECT * FROM TestTable";

                //Read the BFile data.
                byte[]           buffer     = new byte[100];
                OracleDataReader dataReader = command.ExecuteReader();
                using (dataReader)
                {
                    if (dataReader.Read())
                    {
                        OracleBFile BFile = dataReader.GetOracleBFile(1);
                        using (BFile)
                        {
                            BFile.Seek(0, SeekOrigin.Begin);
                            BFile.Read(buffer, 0, 100);
                        }
                    }
                }
            }
            return;
        }
Esempio n. 2
0
        public byte[] GetChunk(int bytes)
        {
            var buffer    = new byte[bytes];
            var bytesRead = _bfile.Read(buffer, 0, bytes);
            var result    = new byte[bytesRead];

            Array.Copy(buffer, 0, result, 0, bytesRead);
            return(result);
        }
        private void get_bfile(OracleConnection con)
        {
            // this helper gets the bfile from the database
            // table, displays the property values and
            // writes the content of the file to the console
            string sqlText = "select file_loc from bfile_test";

            // the command object
            OracleCommand cmd = new OracleCommand(sqlText, con);

            // get a data reader for the command object
            OracleDataReader dataReader = cmd.ExecuteReader();

            OracleBFile bfile = null;

            if (dataReader.Read())
            {
                // use the typed accessor to get the bfile
                bfile = dataReader.GetOracleBFile(0);
            }

            // open the file
            // try
            // {
            //   bfile.OpenFile();
            // }
            // catch(OracleException ex)
            // {
            //   Console.WriteLine(ex.ToString());
            // }

            // display the property values
            Console.WriteLine("Retrieved bfile from database...");
            Console.WriteLine("  CanRead = " + bfile.CanRead.ToString());
            Console.WriteLine("  CanSeek = " + bfile.CanSeek.ToString());
            Console.WriteLine("  CanWrite = " + bfile.CanWrite.ToString());
            Console.WriteLine("  Connection = " + bfile.Connection.ConnectionString);
            Console.WriteLine("  DirectoryName = " + bfile.DirectoryName.ToString());
            Console.WriteLine("  FileExists = " + bfile.FileExists.ToString());
            Console.WriteLine("  FileName = " + bfile.FileName.ToString());
            Console.WriteLine("  Length = " + bfile.Length.ToString());
            Console.WriteLine("  Position = " + bfile.Position.ToString());
            Console.WriteLine("  Value = " + bfile.Value.ToString());

            // convert the byte array to a string
            UTF7Encoding utf = new UTF7Encoding();

            byte[] bf = new byte[bfile.Length];
            bfile.Read(bf, 0, Convert.ToInt16(bfile.Length));
            bfile.Close();
            Console.WriteLine("  Value = \n" + utf.GetString(bf));
        }