Function ConvertWindowsPathToUrl(WindowsPathAndFilename As String) As String
Dim ReturnValue As String = WindowsPathAndFilename
'Make sure the file really exists.
If My.Computer.FileSystem.FileExists(WindowsPathAndFilename) = True Then
Dim WindowsFileInfo As IO.FileInfo = My.Computer.FileSystem.GetFileInfo(WindowsPathAndFilename)
Dim WindowsFullFilename = WindowsFileInfo.FullName
Dim ThisPageWindowsPath As String = Request.PhysicalPath
Dim ThisPageFileInfo As IO.FileInfo = My.Computer.FileSystem.GetFileInfo(ThisPageWindowsPath)
Dim ThisPageFolder As String = ThisPageFileInfo.Directory.FullName
Dim ThisPageUrl As String = Page.ResolveClientUrl(Request.CurrentExecutionFilePath)
Dim ThisPageUrlFolder As String = System.Web.VirtualPathUtility.GetDirectory(ThisPageUrl)
If WindowsFullFilename.Contains(ThisPageFolder) = True Then
'Only return a URL if the path to the file is the same as or under the path to this page.
Dim UrlText As String = WindowsFullFilename
UrlText = UrlText.Replace(ThisPageFolder & "\", ThisPageUrlFolder)
UrlText = UrlText.Replace("\", "/")
UrlText = System.Uri.EscapeUriString(UrlText)
ReturnValue = UrlText
End If
End If
Return ReturnValue
End Function
Tips and tricks for .NET using ASP and VB code.
Convert a Windows path to a URL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment