Uploading File Contents(DOC,PDF,.IMG) to oracle Using ASP.NET

Example:--I Have a WEBFORM WHich conatins FileUploadControl

I Want to Upload Any type of File(PDF,DOC,.IMG) COntents to Oracle Directly (I Do not want to save file in hard disk)

Similarly i want to retrieve the File from Oracle.

Who is Participating?
Ashish PatelCommented:
This is some skeleton code to do it. You should be able to get the general idea, I had to strip a
quite a bit of stuff out as to not give certain things away.

*Note* if your files are larger than 4MB you will need to edit the
httpResponse size in web.config else you will recieve and "action canelled"
or "page not found" error

Private Function InsertBlob(ByVal lngFormSeq As Integer) As Boolean
' Inserts a blob (binary file) into the database.

Dim strSQL As String
strSQL = "SELECT Form_Seq, Word_Document_Blob FROM oracleBlobTable " & _
"WHERE Form_Seq = " & lngFormSeq
Dim daBlob As New OracleDataAdapter(strSQL, connOra)
Dim cb As OracleCommandBuilder = New OracleCommandBuilder(daBlob)
Dim ds As New DataSet

Dim fs As New FileStream("C:\FileName.doc", FileMode.OpenOrCreate,
Dim bBlobStorage(fs.Length) As Byte
fs.Read(bBlobStorage, 0, fs.Length)
daBlob.Fill(ds, "oracleBlobTable")
Dim dr As DataRow = ds.Tables("oracleBlobTable").NewRow
dr("Form_Seq") = lngFormSeq
dr("Word_Document_Blob") = bBlobStorage
daBlob.Update(ds, "oracleBlobTable")

InsertBlob = True
End Function

Private Function RetrieveBlob(ByVal lngFormSeq As Integer) As Boolean
' Retrieves a binary file from the database.

Dim comGetBlob As New OracleCommand
Dim bufferSize As Integer = 8192
Dim outbyte(bufferSize - 1) As Byte 'Byte array for Blob data
Dim strSQL As String
Dim startIndex As Long = 0
Dim retval As Integer

Dim fs As FileStream
Dim bw As BinaryWriter

strSQL = "SELECT Word_Document_Blob FROM oracleBlobTable " & _
"WHERE Form_Seq = " & lngFormSeq

comGetBlob.CommandType = CommandType.Text
comGetBlob.CommandText = strSQL
comGetBlob.Connection = connOra

Dim rdrGetBlob As OracleDataReader =
comGetBlob.ExecuteReader(CommandBehavior.Sequentia lAccess)

If Not rdrGetBlob.HasRows Then
Script_Literal.Text = HandleException(ErrFAFileNotFound)
Exit Function
End If

Do While rdrGetBlob.Read()
fs = New FileStream(conDefaultSaveDir & strDestFileName,
FileMode.OpenOrCreate, FileAccess.Write)
bw = New BinaryWriter(fs)

startIndex = 0
retval = rdrGetBlob.GetBytes(0, startIndex, outbyte, 0, bufferSize)
Do Until Not retval = bufferSize
bw.Write(outbyte) ' Write to file
bw.Flush() ' Clear Writer
outbyte.Clear(outbyte, 0, bufferSize)
startIndex += bufferSize
retval = rdrGetBlob.GetBytes(0, startIndex, outbyte, 0, bufferSize)
bw.Write(outbyte, 0, retval - 1) ' Write to file
rdrGetBlob = Nothing
RetrieveBlob = True
End Function
Ashish PatelCommented:
You will have to store the file as binary in ORACLE and READ binary from ORACLE table. The table column can be of type BLOB.
Jai STech ArchCommented:
this tutorial will guide you to save
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Petrofac_ITlogmeinAuthor Commented:
Can You Please Give Me Some Code Examples Through Which I Can Refer to For PDF and Image Files
Forced accept.

EE Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.