Home » , » How to Store Word Document in Oracle 10G - How to use CLOB/BLOB in Oracle 10G in asp.net,vb.net,C#.net?

How to Store Word Document in Oracle 10G - How to use CLOB/BLOB in Oracle 10G in asp.net,vb.net,C#.net?

Written By M.L on திங்கள், 28 நவம்பர், 2011 | நவம்பர் 28, 2011

I need to store physical Word document in oracle column which defined with one of data type CLOB/BLOB using ASP.Net and C#.

Your help defiantly help me lot

REPLY :1

This would help to upload a document to BLOB data type field in oracle.
Use .Net framework 2.0 and Oracle DB.

Code start from here
            Dim strFilename As String = FileUpLoad1.FileName
            If FileUpLoad1.HasFile Then
                FileUpLoad1.SaveAs(strFullPath)
  lblupload.Text = "File Uploaded: " & FileUpLoad1.FileName & " Content Type " &   FileUpLoad1.PostedFile.ContentType & " Length " & FileUpLoad1.PostedFile.ContentLength
                strUploadMode = "Uploaded"
                strUploadType = FileUpLoad1.PostedFile.ContentType
                                   strUploadExt=Getfileextension(strFullPath)
    ‘Getting connectionstring
            Dim strconnString As String = ConfigurationManager.AppSettings("Connstring")
            Using connOra As New OracleClient.OracleConnection(strconnString)
                Dim blobparameter As New OracleClient.OracleParameter()
                blobparameter.OracleType = Data.OracleClient.OracleType.Blob
                blobparameter.ParameterName = "BlobParameter"           
                    Dim iResult As Int32
                    Dim buf As Byte()
                    Dim fStream As System.IO.FileStream
                    Dim iLength As Integer
                    Dim sFile As String = strFilename
                    Dim sFileAndPath As String = strFullPath
                    fStream = New System.IO.FileStream(strFullPath, FileMode.Open, FileAccess.Read)
                    iLength = fStream.Length - 1
                    fStream.Position = 0
                    buf = New Byte(iLength) {}
                    fStream.Read(buf, 0, iLength)
                    fStream.Close()               
                    blobparameter.Value = buf

                    Dim strUpdateStmt As String = "UPDATE <tablename> SET <column1> = " & " :BlobParameter  " & ", <Column2> = '" & strUploadExt & '
                    Dim cmdOra As New OracleClient.OracleCommand(strUpdateStmt, connOra)
                    cmdOra.Parameters.Add(blobparameter)
                    cmdOra.CommandType = CommandType.Text
                    Try                  
                        connOra.Open()
                        cmdOra.ExecuteNonQuery()                 
                    Catch ex As Exception                
                        Response.Write("Error”)
                    End Try
  
I hope this sample code would help.

-Shafeek.

Note : Provide your comments by clicking beloe options! Thanks ! :)

4 comments:

  1. For the upload to be successful the documents table must be created with the following structure:

    CREATE TABLE documents (
    name VARCHAR2(256) UNIQUE NOT NULL,
    mime_type VARCHAR2(128),
    doc_size NUMBER,
    dad_charset VARCHAR2(128),
    last_updated DATE,
    content_type VARCHAR2(128),
    blob_content BLOB
    )
    /
    Codes for uploading file in C#
    protected void UploadButton_Click(object sender, EventArgs e) { // Specify the path on the server to // save the uploaded file to. String savePath = @"c:\temp\uploads\"; if (FileUpload1.HasFile) { // Get the name of the file to upload. String fileName = FileUpload1.FileName; string extension = System.IO.Path.GetExtension(fileName); if ((extension == ".doc") || (extension == ".xls")) { savePath += fileName; UploadStatusLabel.Text = "Your file was uploaded successfully."; } Else if { // Notify the user why their file was not uploaded. UploadStatusLabel.Text = "Your file was not uploaded because " + "it does not have a .doc or .xls extension."; } // Append the name of the file to upload to the path. savePath += fileName; FileUpload1.SaveAs(savePath); UploadStatusLabel.Text = "Your file was saved as " + fileName; } else { // Notify the user that a file was not uploaded. UploadStatusLabel.Text = "You did not specify a file to upload."; } }

    பதிலளிநீக்கு
  2. How to Store Word Document in Oracle 10G - How to use CLOB/BLOB in Oracle 10G in vb6?

    பதிலளிநீக்கு
  3. 'Please rpovide your comments for Improve this site.'


    This itself is wrong. Its not 'rpovide' - provide

    பதிலளிநீக்கு

Popular Posts

General Category