• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2206
  • Last Modified:

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.

0
Petrofac_ITlogmein
Asked:
Petrofac_ITlogmein
1 Solution
 
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.
0
 
Jai STech ArchCommented:
this tutorial will guide you to save
http://www.codeproject.com/useritems/Blobfield.asp
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Petrofac_ITlogmeinAuthor Commented:
Can You Please Give Me Some Code Examples Through Which I Can Refer to For PDF and Image Files
0
 
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
'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
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now