UNC Path Name

  • Thread starter Thread starter Chris Dunaway
  • Start date Start date
C

Chris Dunaway

Hi

How do I determine the UNC path of a file in VB.NET.
for example if I am given "D:\folder\file.txt", I want to obtain
"\\Computer\Drive\Folder\file.txt"

Tim

Step 1: Make sure your computers Date/Time are set correctly.

Chris
 
Use the Microsoft Scripting Active X control. It has a
Scripting.FileSystemObject object. The object has a GetDrive method that
would work for you.

Dmitry
 
Tim,

The UNC is made up of the format \\server\sharename
(Sorry Chris, it has nothing to do with the time)
Although there must be a way to get access to the collection of system
shares (I don't know the method name), I can't imagine how you will know for
sure that a particular share is pointing absolutely to the file or folder
you want. You would not be able to simply test each share for the word
"System" and know for certain that you are in the Windows system directory
(for instance). Remember that at install time you can name folders anything
you want to name them. Shares and UNC(s) are designed specifically to allow
a program to redirect its connections to various files on various servers or
machines. I think that a share name or UNC needs to be specifically
specified and verified by a human before use.

Regards
 
Tim,

The UNC is made up of the format \\server\sharename
(Sorry Chris, it has nothing to do with the time)
Although there must be a way to get access to the collection of system
shares (I don't know the method name), I can't imagine how you will know for
sure that a particular share is pointing absolutely to the file or folder
you want. You would not be able to simply test each share for the word
"System" and know for certain that you are in the Windows system directory
(for instance). Remember that at install time you can name folders anything
you want to name them. Shares and UNC(s) are designed specifically to allow
a program to redirect its connections to various files on various servers or
machines. I think that a share name or UNC needs to be specifically
specified and verified by a human before use.

Regards
 
(Sorry Chris, it has nothing to do with the time)

I was referring to the fact that his post was dated Oct 2, 2003. I wanted
him to correct his computers date/time before posting.

Chris
 
Hi Tim,

Thanks for your post. As I understand, you share a folder on the local
machine and want to get its corresponding UNC path. Please correct me if
there is any misunderstanding. Now I'd like to share the following
information with you:

We are able to call WNetEnumResource to enumerate the network resources.
Since there is no corresponding class to handle network sharing .NET, I
suggest that you can use P/Invoke to call WNetEnumResource() API to
determine to which a specific local name is mapped to a remote name of a
shared folder. I believe the following article and sample are helpful:

WNetEnumResource API
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/w
netenumresource.asp

WNetEnumResource sample
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=741&lngW
Id=10

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
In NT based systems, the drives are shared as follows:

\\ComputerName\C$
\\ComputerName\D$

These are admin shares and have special permissions assigned to them, you
may be able to use those.

You can determine the computer name with System.Net.Dns.GetHostName

Then, extract the drive from the file-path.

UNCPath = "\\" & ComputerName & "\" & Drive & "$\Folder\File"

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"


: Hi
:
: How do I determine the UNC path of a file in VB.NET.
: for example if I am given "D:\folder\file.txt", I want to obtain
: "\\Computer\Drive\Folder\file.txt"
:
: Tim
:
:
 
Hi

How do I determine the UNC path of a file in VB.NET.
for example if I am given "D:\folder\file.txt", I want to obtain
"\\Computer\Drive\Folder\file.txt"

Tim
 
Back
Top