Created
March 18, 2013 14:17
-
-
Save garethflowers/5187446 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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