Connecting Tech Pros Worldwide Forums | Help | Site Map

upload file to Oracle DB

Mike
Guest
 
Posts: n/a
#1: Nov 19 '05
has anyone uploaded a document such as word to an Oracle table? if so where
can i find an example of this being done in VB.NET

Steve C. Orr [MVP, MCSD]
Guest
 
Posts: n/a
#2: Nov 19 '05

re: upload file to Oracle DB


This article explains the process of uploading files directly into SQL
Server and getting them back out again:
http://steve.orr.net/content/asp200307so_f.asp

I'd imagine it wouldn't take much modification to get it working with
Oracle.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


"Mike" <Mike@discussions.microsoft.com> wrote in message
news:0A4C6D47-3CB0-4F83-AB5E-C7120FF324C1@microsoft.com...[color=blue]
> has anyone uploaded a document such as word to an Oracle table? if so
> where
> can i find an example of this being done in VB.NET[/color]


Fletch Padgett
Guest
 
Posts: n/a
#3: Nov 19 '05

re: upload file to Oracle DB


This is some skeleton code to do it. I have this in production and it works
like a charm. 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
'DESCRIPTION:
' Inserts a blob (binary file) into the database.
'

Dim strSQL As String
Try
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,
FileAccess.Read)
Dim bBlobStorage(fs.Length) As Byte
fs.Read(bBlobStorage, 0, fs.Length)
fs.Close()
daBlob.Fill(ds, "oracleBlobTable")
Dim dr As DataRow = ds.Tables("oracleBlobTable").NewRow
dr("Form_Seq") = lngFormSeq
dr("Word_Document_Blob") = bBlobStorage
ds.Tables("oracleBlobTable").Rows.Add(dr)
daBlob.Update(ds, "oracleBlobTable")

ds.Dispose()
daBlob.Dispose()
InsertBlob = True
End Function

Private Function RetrieveBlob(ByVal lngFormSeq As Integer) As Boolean
'DESCRIPTION:
' 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)
Loop
bw.Write(outbyte, 0, retval - 1) ' Write to file
bw.Flush()
Loop
rdrGetBlob.Close()
rdrGetBlob = Nothing
comGetBlob.Dispose()
RetrieveBlob = True
End Function


"Mike" wrote:
[color=blue]
> has anyone uploaded a document such as word to an Oracle table? if so where
> can i find an example of this being done in VB.NET[/color]
Closed Thread