Hi
i am trying to open a pdf file using vb.net with the following code. it gives an error messages at ar.src=splitout(i) and the message is "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.". please help.
Thanks
Dim dlg As OpenFileDialog = New OpenFileDialog()
dlg.ShowDialog()

If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim filestream As StreamReader = New StreamReader(dlg.OpenFile, System.Text.Encoding.Default)

Dim readcontents As String
readcontents = filestream.ReadToEnd()

Dim textdelimiter As String

textdelimiter = (" ")
Dim splitout() As String = Split(readcontents, textdelimiter)
Dim i As Integer
For i = 0 To UBound(splitout)
AR.src = splitout(i)
AR.Refresh()

System.Threading.Thread.Sleep(500)
Next

filestream.Close()
End If

Recommended Answers

All 5 Replies

Member Avatar for iamthwee

It is a bad idea trying to read pdf files because the text could have been generated in any way.

Hi
Do u mean that the pdf file needs to converted to a text file before reading?

Thanks

Member Avatar for iamthwee

Possibly yes

Imports System.IO

Public Class SaveClass
    Public Function GetContents(ByVal FullPath As String)
        Dim contents As String
        Dim read As StreamReader
        Try
            read = New StreamReader(FullPath)
            contents = read.ReadToEnd
            read.Close()
            Return contents
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Function

    Public Function SaveTextToFile(ByVal strData As String, _
     ByVal FullPath As String) As Boolean

        Dim objReader As StreamWriter
        Try
            objReader = New StreamWriter(FullPath, True)
            objReader.WriteLine(strData)
            objReader.Close()
            Return True
        Catch Ex As Exception
            Return False
        End Try
    End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.