Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2923
  • Last Modified:

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
0
Éric Moreau
Asked:
Éric Moreau
  • 2
1 Solution
 
bruintjeCommented:
Hello emoreau,


there is a .net way in a sample class that enumerates the shares here
source: http://www.codeproject.com/csharp/networkshares.asp?df=100&forumid=9166&exp=0&select=860112

or a WMI way
source: http://www.dotnet247.com/247reference/msgs/28/143069.aspx

---------
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
bruintje
0
 
Éric MoreauSenior .Net ConsultantAuthor Commented:
It would be helpful from MS to put this into System.IO.Something !
0
 
bruintjeCommented:
uhm yes, haven't looked yet but maybe in the new mycomputer class

thanks for the grade :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now