Transform a path into a UNC path

Posted on 2006-04-28
Last Modified: 2012-06-22
How can I transform a local path to its UNC representation (VB.Net 2003) ?
Ex: j:\folder\test.txt  ---->>>> \\servername\sharename\folder\test.txt
Question by:Éric Moreau
    LVL 44

    Accepted Solution

    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
    LVL 69

    Author Comment

    by:Éric Moreau
    It would be helpful from MS to put this into System.IO.Something !
    LVL 44

    Expert Comment

    uhm yes, haven't looked yet but maybe in the new mycomputer class

    thanks for the grade :)

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now