473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

UNC Path Name

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
7 19012
"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
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
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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Bengt dePaulis | last post by:
I have a local directory that I want to include in my sys.path How to save it permanently? Regards /Bengt
2
by: Steven Burn | last post by:
Oks, I know I'm going to seem completely stupid here but, I have a question thats been doing my head in for the last few hours. Basically, I'm trying to find a way to turn a folder and file path,...
8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
70
by: Michael Hoffman | last post by:
Many of you are familiar with Jason Orendorff's path module <http://www.jorendorff.com/articles/python/path/>, which is frequently recommended here on c.l.p. I submitted an RFE to add it to the...
34
by: Reinhold Birkenfeld | last post by:
Hi, the arguments in the previous thread were convincing enough, so I made the Path class inherit from str/unicode again. It still can be found in CVS:...
1
by: Matt | last post by:
In test() method: var path="C:\test\hello.txt"; //returns -1 for path.lastIndexOf("\\"). why?? var pos=path.lastIndexOf("\\"); //return -1 But in showFile() method: We are able to get the...
2
by: Csharper95 | last post by:
I want to get the file name and path from a SaveFileDialog (for a 'save as' operation) after the user has saved the information under a new file name (and presumably under a new path) ? I want...
11
by: cdkorzen | last post by:
I'm sorry if this is a rehash, but all I see is the same info. Here's my debacle: I CAN get the PATH_INFO to work. With ANYTHING but ASP. Python, Perl, Cmd files... works fine. ASP can't...
2
by: zz12 | last post by:
Hello. We have a SearchResults.asp page that returns a list of asp pages that are associated with the user's search parameters that they type in in a search page called something like Search.asp. ...
8
by: moondaddy | last post by:
I'm posting code for a user control ( FunctionConnectorSelector) below which has 3 content controls in it. each content control uses a style from a resource dictionary merged into the app.xaml...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.