views:

132

answers:

2

Greetings everyone, i've been searching for awhile now and nothing seems to satisfy my desired output... All i want to achieved is to get the whole and same content of any file i uploaded, for my editing purposes in my editor w/c retrieves file from the database.

i.e of files are ".doc and .txt"and by the way what i meant by same content is the whole same appearance of my .doc or .txt file i.e "if the text is bold, forecolor is red and etc.."

i successfully established a file upload and a function to store it in a database... but what i'm missing is the whole and same content of the file. Another thing is i don't want the file to be saved in a local folder or somewhere..i just want it to be save directly to my database

Below is my sample code of trying to retrieve the content.. but it is an error when you run.. please correct me

Private Sub cmdSave_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    If filMyFile.PostedFile IsNot Nothing Then
        Dim fs As FileStream
        Dim val As String

        Dim nFileLen As Integer = myFile.ContentLength

        If nFileLen > 0 Then

        Dim myData As Byte() = New Byte(nFileLen - 1) {}

        fs = File.Open(myFile.FileName, FileMode.Open, FileAccess.Read)

        Dim cont As StreamReader                    
        cont = New StreamReader(fs)
        cont.BaseStream.Seek(0, SeekOrigin.Begin)


        While cont.Peek() > -1

        val &= cont.ReadLine()

        End While
        cont.Close()

                myFile.InputStream.Read(myData, 0, nFileLen)
                ' Store it in database
                Dim nNewsID As Integer = WriteToDB(strFilename, val, myData)
        End If              
    End If
End Sub

Private Function WriteToDB(ByVal strName As String, ByVal strContent As String, ByRef Buffer As Byte()) As Integer
    'some codes here .....
End Function

Any suggestion or advise is highly sought... Thank You and God Bless