Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb6 and WebBrowser Control

Posted on 2014-03-25
2
Medium Priority
?
678 Views
Last Modified: 2014-03-26
Hi Guys

Using vb6 and the Web Browser Control.

I load a word document into the web browser control.

I try to get the filname of the currently opened file using the following code:

Function GetDocumentName()
    Dim szFullFileName$
    szFullFileName = wb.LocationURL
    MsgBox szFullFileName & vbCrLf & wb.LocationURL
End Function

Open in new window


szFullFilename will refer to the url of the file in the following format:

file:///E:/Code/TimeKeeper/tmp_%20160616.doc

This is URL Encoded.

I need to decode the LocationURL to return the actual file name, including a filename which might be UNC.

Any and all help appreciated.

MTIA


DWE

(PS I note that in the wb_DocumentComplete event, the URL value is the actual filename, not the URLEncoded version)
0
Comment
Question by:dwe0608
[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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 39955308
you will need the following things:
1) a urldecode function like this one:
http://www.vb-helper.com/howto_url_decode_string.html
' Convert a URL safe encoding into its original text.
Private Function URLDecode(ByVal txt As String) As String
Dim txt_len As Integer
Dim i As Integer
Dim ch As String
Dim digits As String
Dim result As String

    SetSafeChars

    result = ""
    txt_len = Len(txt)
    i = 1
    Do While i <= txt_len
        ' Examine the next character.
        ch = Mid$(txt, i, 1)
        If ch = "+" Then
            ' Convert to space character.
            result = result & " "
        ElseIf ch <> "%" Then
            ' Normal character.
            result = result & ch
        ElseIf i > txt_len - 2 Then
            ' No room for two following digits.
            result = result & ch
        Else
            ' Get the next two hex digits.
            digits = Mid$(txt, i + 1, 2)
            result = result & Chr$(CInt("&H" & digits))
            i = i + 2
        End If
        i = i + 1
    Loop

    URLDecode = result
End Function

Open in new window

2) remove the file:// prefix
3) eventually replace the / by \  in the resulting string.
0
 
LVL 1

Author Comment

by:dwe0608
ID: 39955489
Thanks Guy

Attached is the code - can be made better of course but it does the job - no doubt someone here will find it useful or make it better .... I have left the original credits in the zip file which contains a small project which demonstrates the use of the function ....

Regards

DWE

' Convert a URL safe encoding into its original text.
Private Function URLDecode(ByVal txt As String) As String
Dim txt_len As Integer
Dim i As Integer
Dim ch As String
Dim digits As String
Dim result As String

    result = ""
    txt_len = Len(txt)
    i = 1
    Do While i <= txt_len
        ' Examine the next character.
        ch = Mid$(txt, i, 1)
        If ch = "+" Then
            ' Convert to space character.
            result = result & " "
        ElseIf ch <> "%" Then
            ' Normal character.
            result = result & ch
        ElseIf i > txt_len - 2 Then
            ' No room for two following digits.
            result = result & ch
        Else
            ' Get the next two hex digits.
            digits = Mid$(txt, i + 1, 2)
            result = result & Chr$(CInt("&H" & digits))
            i = i + 2
        End If
        i = i + 1
    Loop

    URLDecode = ReFormatFilePart(result)
End Function

Function ReFormatFilePart(s As String) As String

    s = Replace(s, "file:///", "")
    s = Replace(s, "/", "\")
    
    ReFormatFilePart = s

End Function

Function GetDocumentName()
    Dim szFullFileName$
    szFullFileName = URLDecode(wb.LocationURL)
    Debug.Print szFullFileName & vbCrLf & wb.LocationURL
    
End Function

Open in new window

URLDecode.zip
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Suggested Courses

670 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