Solved

how to read rtf file in webBrowser control?

Posted on 2002-07-19
7
681 Views
Last Modified: 2010-08-05
I've got a small app (both Access 2000 and VB6) that uses a web Browser control to navigate to a variety of sites.  I then parse the table info or text from the html and populate an Access table.

My problem is that one site that I need ends up delivering an rtf file.  My web Browser control loads the rtf file ok, but I can't seem to find the proper syntax, object properties, methods, etc. to then read the text.

Optionally, I could load the file to a RichTextBox control, but I can't seem to make the .LoadFile method of the RichTextBox control find the file on the internet site.


Any suggestions?

note: I've already tried "webBrowser.document.documentElement.innerHtml" or innerText or just "webBrowser.document.body.innerText" and gotten the error message:
"Object doesn't support this property or method."

It seems that once the rtf file is loaded, all of the normal webBrowser.document properties and methods are invalid.

0
Comment
Question by:PatOBrien
  • 3
  • 3
7 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7165801
To some extents, yes. i don't know if there is a "DOM" for rtf file format.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7165911
Well, as long as i can see, we could manage it like a word document, could you do a check?
(we have to use a better way to know which type of doc is but for testing, this would be enougth, wb1 is webbrowser control. We have to set a reference to microsoft word object library in the project)


Private Sub wb1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is wb1.Object) Then
    If Right$(wb1.Document.Name, 3) = "rtf" Then
        Dim wrtf As Word.Document
        Set wrtf = wb1.Document
       
    End If
End If
End Sub

Do an inspection over wrtf var and see...
0
 
LVL 27

Accepted Solution

by:
Ark earned 150 total points
ID: 7166326
Hi

Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nSize As Long, ByVal lpBuffer As String) As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
       "URLDownloadToFileA" (ByVal pCaller As Long, _
       ByVal szURL As String, _
       ByVal szFileName As String, _
       ByVal dwReserved As Long, _
       ByVal lpfnCB As Long) As Long

Public Function URLToTextBox(ByVal sUrl As String, txt As TextBox) As Boolean
  Dim sTemp As String, sHTML As String
  sTemp = GetTempDir & "dummy.html"
  If Dir$(sTemp) <> "" Then Kill sTemp
  Call URLDownloadToFile(0&, sURL, sTemp, 0, 0)
  Open sTemp For Binary As #1
       sHTML = Space(LOF(1))
       Get #1, , sHTML
  Close #1
  Kill sTemp
  txt.Text = sHTML
End Function

Public Function URLToRTB(ByVal sUrl As String, rtb As RichTextBox) As Boolean
  Dim sTemp As String, sHTML As String
  sTemp = GetTempDir & "dummy.rtf"
  If Dir$(sTemp) <> "" Then Kill sTemp
  Call URLDownloadToFile(0&, sURL, sTemp, 0, 0)
  rtb.LoadFile sTemp, rtfRTF
  Kill sTemp
End Function

Private Function GetTempDir() As String
  Dim tmp As String
  tmp = Space$(256)
  Call GetTempPath(Len(tmp), tmp)
  GetTempDir = TrimNull(tmp)
End Function

Private Function TrimNull(item As String)
  Dim pos As Integer
  pos = InStr(item, Chr$(0))
  If pos Then
     TrimNull = Left$(item, pos - 1)
  Else
     TrimNull = item
  End If
End Function


0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Author Comment

by:PatOBrien
ID: 7169769
Richie,

It appears that it can (does) come in as Word Document.

What's next?


Ark,

I'll be trying your functions today.... will let you know what I find.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7169933
RTF could be read  to some extents as a Word Document
Better use Ark's code.
Cheers
0
 
LVL 5

Author Comment

by:PatOBrien
ID: 7170460
.... help me go in the right direction.

I added some "On Error" statements and set the function values.

Thanks.
0
 
LVL 5

Author Comment

by:PatOBrien
ID: 7175707
I meant that it "...helped me go in the right direction.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

11 Experts available now in Live!

Get 1:1 Help Now