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

Code

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 alextriantf@yahoo.gr
'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)
Else
  StripTerminator = sInput
End If
End Function

About this post

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

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.