VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Create URL from Path (URLCreateFromPath API)

by Alexander Triantafyllou (5 Submissions)
Category: Internet/HTML
Compatability: VB Script
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

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

Rate Create URL from Path (URLCreateFromPath API)

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 [email protected]
'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

Download this snippet    Add to My Saved Code

Create URL from Path (URLCreateFromPath API) Comments

No comments have been posted about Create URL from Path (URLCreateFromPath API). Why not be the first to post a comment about Create URL from Path (URLCreateFromPath API).

Post your comment

Subject:
Message:
0/1000 characters