Transform a path into a UNC path

How can I transform a local path to its UNC representation (VB.Net 2003) ?
Ex: j:\folder\test.txt  ---->>>> \\servername\sharename\folder\test.txt
LVL 71
Éric MoreauSenior .Net ConsultantAsked:
Who is Participating?
Hello emoreau,

there is a .net way in a sample class that enumerates the shares here

or a WMI way

Imports System.Text
Imports System.Runtime.InteropServices

Module Module1

<DllImport("mpr.dll", SetLastError:=False, CharSet:=CharSet.Auto)> _
Function WNetGetConnection( _
  ByVal localName As String, _
  ByVal remoteName As StringBuilder, _
  ByRef remoteSize As Int32) As Int32
End Function

Sub Main()
  Dim sb As New StringBuilder(300)
  Dim size As Int32 = sb.Capacity
  WNetGetConnection("Z:", sb, size)
  Console.WriteLine("Local : Z Remote : {0}", sb.ToString)
End Sub

End Module

hope this helps a bit
Éric MoreauSenior .Net ConsultantAuthor Commented:
It would be helpful from MS to put this into System.IO.Something !
uhm yes, haven't looked yet but maybe in the new mycomputer class

thanks for the grade :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.