Solved

vb6 and WebBrowser Control

Posted on 2014-03-25
2
624 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 500 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

Technology Partners: 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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

737 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