I've got a number of users who publish data to the intranet by copying it
onto a server then making links to it.
I'd like to make a script for the people who are finding it a little
confusing to convert the UNC of the file into a URL.
Here's an example:
UNC: \\web1a\PIBReports\BCA\Admin_Reports\User_List.pdf
URL: http://web1/pibreports/bca/admin_reports/user_list.pdf
I realise this is a pretty basic one but I'm still having trouble with it!
Any help much appreciated.
Cheers,
Pete
--
Cheers,
Foss
Function GetUrlFromUnc(Unc)
Const BASE_URL = "http://web1/"
Const BASE_FOLDER = "pibreports"
Dim iPos
iPos = InStr(1, Unc, BASE_FOLDER, vbTextCompare)
If iPos > 0 Then
Dim sSubPath
sSubPath = Mid(Unc, iPos)
sSubPath = Replace(sSubPath, "\", "/")
GetUrlFromUnc = BASE_URL & sSubPath
Else
'Invalid Folder
GetUrlFromUnc = ""
End If
End Function
Dim sInitialUnc
sInitialUnc = "\\web1\PIBReports\BCA\Admin_Reports\User_List.pdf"
WScript.echo GetUrlFromUnc(sInitialUnc)
--
Joe (MVP)
Is the URL's "web1" supposed to be "web1a" like the UNC?
UNC: \\web1a\PIBReports\BCA\Admin_Reports\User_List.pdf
URL: http://web1/pibreports/bca/admin_reports/user_list.pdf
If so then perhaps you want:
URL = "http:" & Replace(UNC,"\","/")
This also presumes that case sensitibvity is not an issue.
That's perfect! Thank you very much.. Thankfully, PIBReports is a share so
that'll always be there and your script works perfectly!
Cheers,
Pete
> Hi there Joe,
>
> That's perfect! Thank you very much.. Thankfully, PIBReports is a
> share so that'll always be there and your script works perfectly!
Hi
You might want to use the undocumented Escape function to url
encode the path (e.g. a space will be converted to %20):
'--------------------8<----------------------
sUNC = "\\web1a\PIBReports\BCA\Admin_Reports\User_List.pdf"
' Replace \ with /
sTmp = Replace(sUNC, "\", "/")
' url encode sTmp using the undocumented Escape function
sURL = "http:" & Escape(sTmp)
MsgBox sURL
'--------------------8<----------------------
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
The UNC and URLs I wrote are correct I'm afraid.
There are three servers web1a, b and c. These, I think, are all used to feed
the http://web1 intranet home page. This makes it a little more confusing but
not too bad!
Thanks very much, that's going to be useful for something else I'm doing
later as well!
Cheers,
Pete
Here's the completed mixture of suggestions in case it's of interest:
'-----------------------------------
Function GetUrlFromUnc(Unc)
Const BASE_URL = "http://web1/"
Const BASE_FOLDER = "pibreports"
Dim iPos
iPos = InStr(1, Unc, BASE_FOLDER, vbTextCompare)
If iPos > 0 Then
Dim sSubPath
sSubPath = Mid(Unc, iPos)
sSubPath = Replace(sSubPath, "\", "/")
sSubPath = Escape(sSubPath)
GetUrlFromUnc = BASE_URL & sSubPath
Else
'Invalid Folder
GetUrlFromUnc = ""
End If
End Function
strCopy = GetUrlFromUnc(InputBox("Please enter the file path"))
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text", strCopy
objIE.Quit
msgbox("The HyperLink (URL) to your file has been copied to the clipboard,
please use the Paste command on the Edit menu or 'CTRL+V' to use it." +
Chr(10) + strCopy)
'-----------------------------------
URL = "http:" & lcase( Replace(UNC,"\","/") )
/Al
'-------------------------------------------------------------
on error resume next
Function GetUrlFromUnc(Unc)
Const BASE_URL = "http://web1/"
Const BASE_FOLDER = "pibreports"
Dim iPos
iPos = InStr(1, Unc, BASE_FOLDER, vbTextCompare)
If iPos > 0 Then
Dim sSubPath
sSubPath = Mid(Unc, iPos)
sSubPath = Replace(sSubPath, "\", "/")
sSubPath = Escape(sSubPath)
GetUrlFromUnc = lcase(BASE_URL & sSubPath)
Else
'Invalid Folder
GetUrlFromUnc = ""
End If
End Function
AppCap = "Convert File Path to HyperLink"
strCopy = GetUrlFromUnc(InputBox("Please enter the file
path",AppCap,"\\web1a\PIBReports\"))
If strCopy <> "" Then
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text", strCopy
objIE.Quit
MsgBox "The HyperLink (URL) to your file has been copied to the clipboard,
please use the Paste command on the Edit menu or 'CTRL+V' to use it." +
Chr(10) + strCopy, 64, AppCap
Else
End If
'-------------------------------------------------------------