Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to read rtf file in webBrowser control?

Posted on 2002-07-19
7
Medium Priority
?
736 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 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