Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const MAX_PATH As Long = 260
Private Const ERROR_SUCCESS As Long = 0
Private Declare Function UrlCreateFromPath Lib "shlwapi" _
Alias "UrlCreateFromPathA" _
(ByVal pszPath As String, _
ByVal pszUrl As String, _
pcchUrl As Long, _
ByVal dwReserved As Long) As Long
Private Sub Form_Load()
Text1.Text = "http://vbnet code lib/net code/../ip address.htm"
Text1.Text = "c:\my documents\vbnet articles\random access.doc"
Text2.Text = ""
Text3.Text = "c:\documents\vbnet\randomaccess.doc"
Text4.Text = ""
Text5.Text = "\\192.168.1.102\vbnet\randomaccess.htm"
Text6.Text = ""
Command1.Caption = "Create From Path"
End Sub
Private Sub Command1_Click()
Dim sPath As String
Dim sUrl As String
'use the original string in Text1 for
'demo, and show results in Text2
sPath = Text1.Text
sUrl = CreateUrlFromPath(sPath)
Text2.Text = sUrl
'use the original string in Text3 for
'demo, and show results in Text4
sPath = Text3.Text
sUrl = CreateUrlFromPath(sPath)
Text4.Text = sUrl
'use the original string in Text5 for
'demo, and show results in Text6
sPath = Text5.Text
sUrl = CreateUrlFromPath(sPath)
Text6.Text = sUrl
End Sub
Private Function CreateUrlFromPath(ByVal sPath As String) As String
Dim sUrl As String
Dim dwSize As Long
If Len(sPath) > 0 Then
sUrl = Space$(MAX_PATH)
dwSize = Len(sUrl)
If UrlCreateFromPath(sPath, _
sUrl, _
dwSize, _
0&) = ERROR_SUCCESS Then
CreateUrlFromPath = Left$(sUrl, dwSize)
End If 'If UrlCreateFromPath
End If 'If Len(sUrl) > 0
End Function |