Solved

how to read rtf file in webBrowser control?

Posted on 2002-07-19
7
689 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 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

20 Experts available now in Live!

Get 1:1 Help Now