Search Tools Links Login

Create URL from Path (URLCreateFromPath API)

create an url from a file path
for example
input: "E:/my photo.jpg"
output: "file:///E:/my%20photo.jpg"

Original Author: Alexander Triantafyllou


Private Declare Sub UrlCreateFromPath Lib "shlwapi.dll" Alias "UrlCreateFromPathA" (ByVal pszPath As String, ByVal pszUrl As String, ByRef pcchUrl As Long, ByVal dwFlags As Long)
'create a url from a file path
'for example
'input: "E:/my photo.jpg"
'output: "file:///E:/my%20photo.jpg"
'Alexander Triantafyllou
'BSc Information Technology & Telecommunications
'University of Athens , Greece
const MAX_PATH=260
Public Function url_encode(ByVal str_urlpath As String) As String
Dim out_str As String
Dim str_path As String
out_str = String(MAX_PATH, 0)
str_path = str_urlpath + String(100, 0)

UrlCreateFromPath str_path, out_str, MAX_PATH, 0
out_str = StripTerminator(out_str)

url_encode = out_str
End Function
'Remove all trailing Chr$(0)'s
Function StripTerminator(sInput As String) As String
Dim ZeroPos As Long
ZeroPos = InStr(1, sInput, Chr$(0))
If ZeroPos > 0 Then
  StripTerminator = Left$(sInput, ZeroPos - 1)
  StripTerminator = sInput
End If
End Function

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 127 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.