?
Solved

how to read rtf file in webBrowser control?

Posted on 2002-07-19
7
Medium Priority
?
731 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 28

Accepted Solution

by:
Ark earned 600 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

762 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