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

Posted on 2007-10-09
Last Modified: 2008-03-01
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.

Question by:Petrofac_ITlogmein
    LVL 23

    Expert Comment

    by:Ashish Patel
    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.
    LVL 14

    Expert Comment

    this tutorial will guide you to save
    LVL 14

    Expert Comment


    Author Comment

    Can You Please Give Me Some Code Examples Through Which I Can Refer to For PDF and Image Files
    LVL 23

    Accepted Solution

    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
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now