Skip to content

Instantly share code, notes, and snippets.

@garethflowers
Created March 18, 2013 14:17
Show Gist options
  • Select an option

  • Save garethflowers/5187446 to your computer and use it in GitHub Desktop.

Select an option

Save garethflowers/5187446 to your computer and use it in GitHub Desktop.
Public Shared Function pathAsUnc(ByVal fileName As String) As String
Dim file As New System.IO.FileInfo(filename.ToLowerInvariant)
If Not file.Exists Then
Return String.Empty
End If
Dim oldDrive As String = file.Directory.Root.FullName
Dim uncPath As Object = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Network\" & oldDrive.Remove(1), "RemotePath", Nothing)
Dim uri As Uri
If uncPath Is Nothing Then
uri = New Uri(file.FullName)
Else
uri = New Uri(file.FullName.Replace(oldDrive, uncPath.ToString))
End If
Return uri.AbsoluteUri
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment