By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

UNC Path Name

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Tim Marsden" <TM@UK.COM> wrote in news:O5b8gfCiDHA.2212
@TK2MSFTNGP09.phx.gbl:
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
Nov 20 '05 #2

P: n/a
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

"Chris Dunaway" <du******@lunchmeatsbcglobal.net> wrote in message
news:Xn**********************************@207.46.2 48.16...
"Tim Marsden" <TM@UK.COM> wrote in news:O5b8gfCiDHA.2212
@TK2MSFTNGP09.phx.gbl:
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

Nov 20 '05 #3

P: n/a
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 Marsden" <TM@UK.COM> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #4

P: n/a
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 Marsden" <TM@UK.COM> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #5

P: n/a
"Jerry" <Je*********@yahoo.com> wrote in
news:OH**************@TK2MSFTNGP12.phx.gbl:
(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
Nov 20 '05 #6

P: n/a
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/de...us/wnet/wnet/w
netenumresource.asp

WNetEnumResource sample
http://www.planet-source-code.com/vb...odeId=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.

Nov 20 '05 #7

P: n/a
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"
"Tim Marsden" <TM@UK.COM> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
: 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
:
:
Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.