|
-
Feb 15th, 2006, 09:47 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Identifying a network drive and finding its path
I'm writing a small tool for ArcMap that invokes one of the tools built into it. For some reason though the tool, and Arc in general, is kind of picky when dealing with network drives. Say I have a network share mapped as the P: drive. The share itself is \\Canberra\Projects. Now, when I send a parameter into the tool that lists the path of a file, I need to send it in as \\Canberra\Projects\file.txt rather than P:\file.txt.
I can't be sure in advance what the drive mappings might be for a user, so how do I work out if a drive is a network connection rather than a physical drive and how do I extract the network mapping for that drive?
-
Feb 15th, 2006, 09:50 PM
#2
Re: Identifying a network drive and finding its path
You don't have to worry about it...
*holds for a sigh of releif*
I network shared drive is the same as pathing, just not as easy to explain to an end user. Giving it the full name should work regardless of if the mapped drive is P or E or N or I or..... Q
Cheeky monkey
-
Feb 15th, 2006, 09:53 PM
#3
Thread Starter
Addicted Member
Re: Identifying a network drive and finding its path
I think you've missed my point. The Arc tool I'm invoking will not work correctly if I give it the file path in the form P:\file.txt. It complains that it can't find the file basically. I have to put it in the form \\Canberra\Projects\file.txt.
-
Feb 15th, 2006, 09:53 PM
#4
Re: Identifying a network drive and finding its path
If what you say is true and it will not accept a local path for a network share then you should take a look at this article. I've never had the pleasure myself but I believe that the FileSystemObject and Drive objects should be able to give you the information you're after.
-
Feb 15th, 2006, 09:58 PM
#5
Re: Identifying a network drive and finding its path
I was hoping that VB 2005 might have something better to offer through the DriveInfo class and/or the My.Computer.FileSystem object but it appears not.
-
Feb 15th, 2006, 09:59 PM
#6
Re: Identifying a network drive and finding its path
God has spoke, bow with me 
Strong server name or pathed, it should work if the network path drive is the same. If it's not that, the divine eye of jmc will explain in detail.
*keep your head down, he's not done *
Sarcasm/kidding aside, he knows alot more then I do; i really would like to hear this as well.
Last edited by sevenhalo; Feb 15th, 2006 at 10:05 PM.
Reason: added kidding, seemed less atackggn to me sine i really legitly am asking.
-
Feb 15th, 2006, 10:09 PM
#7
Re: Identifying a network drive and finding its path
 Originally Posted by sevenhalo
God has spoke, bow with me
Strong server name or pathed, it should work if the network path drive is the same. If it's not that, the divine eye of jmc will explain in detail.
*keep your head down, he's not done  *
Sarcasm aside, he knows alot more then I do; i really would like to hear this as well.
I have no idea why it wouldn't worked with a local path either. If you just try to perfrom a file system operation the OS should handle any translation required. That's the whole point of mapping a network share to a drive letter in the first place: so that you can treat it like a local path. If it doesn't work in this case then I can only assume that the authors of this component have done something screwy internally. Bad programming on their part I'd say. If you can access the share via the UNC path then there's no point preventing access via the mapped local path. All I'm saying is that if they have somehow prevented use of mapped local paths for shares then the FSO should be able to give you the information you need to get the UNC path from the local path.
-
Feb 15th, 2006, 10:17 PM
#8
Thread Starter
Addicted Member
Re: Identifying a network drive and finding its path
One of the other Arc products, Arc Catalog, lists drivers/folders in your computers and lets you browse the GIS data therein. It lists physical drives, but not network ones. If you want to access network data you have to tell it the network path for the data. I've absolutely no idea why this is so but it is - it's one of many oddities about the Arc products.
Anyway, details on the FileSystemObject class seem pretty sketchy - is this really in .NET or just VB? I tried the following code:
Dim fso As Object
fso = CreateObject("Scripting.FileSystemObject")
fso.getDrive("P:")
Dim temp = fso.Drive.ShareName
The first three lines work ok, but the last line gives me this error:
"Public member 'Drive' on type 'IFileSystem3' not found."
Ok, I'm guessing that the fso has an interface of type IFileSystem3 - but I can find no details on that at all.
-
Feb 15th, 2006, 10:20 PM
#9
Re: Identifying a network drive and finding its path
You can look for network drives using WMI Here is a short example, uses the Win32_LogicalDisk WMI class. Looks for a DriveType of "4", which is a network drive.
***NOTE - add reference to system.management in order to use
VB Code:
Dim MyobjectQuery As New System.Management.ObjectQuery("select * from Win32_LogicalDisk")
Dim MySearcher As New System.Management.ManagementObjectSearcher(MyobjectQuery)
'loops for all drives on system
For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
'looks for drives with drivetype of 4 which is network drive
If Mgmt("DriveType").ToString = "4" Then
'display caption, which is drive letter
MessageBox.Show(Mgmt("Caption").ToString)
'below should display network drive path, but couldnt test
MessageBox.Show(Mgmt("ProviderName").ToString
End If
Next
For the list of properties for the Win32_LogicalDisk class, check here: http://msdn.microsoft.com/library/de...ogicaldisk.asp
I couldnt test it on a network drive, as I have none, but a drivetype of "5" worked fine for me.
Last edited by gigemboy; Feb 15th, 2006 at 10:25 PM.
-
Feb 15th, 2006, 10:25 PM
#10
Thread Starter
Addicted Member
Re: Identifying a network drive and finding its path
 Originally Posted by gigemboy
You can look for network drives using WMI  Here is a short example, uses the Win32_LogicalDisk WMI class. Looks for a DriveType of "4", which is a network drive.
***NOTE - add reference to system.management in order to use
VB Code:
Dim MyobjectQuery As New System.Management.ObjectQuery("select * from Win32_LogicalDisk")
Dim MySearcher As New System.Management.ManagementObjectSearcher(MyobjectQuery)
'loops for all drives on system
For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
'looks for drives with drivetype of 4 which is network drive
If Mgmt("DriveType").ToString = "4" Then
'display caption, which is drive letter
MessageBox.Show(Mgmt("Caption").ToString)
End If
Next
For the list of properties for the Win32_LogicalDisk class, check here: http://msdn.microsoft.com/library/de...ogicaldisk.asp
I couldnt test it on a network drive, as I have none, but a drivetype of "5" worked fine for me.
Isn't that VB code rather than .NET code? The ManagementObject class in .NET doesn't seem to have the drivetype property. It also doesn't help me find the network path either. Thanks for trying though.
-
Feb 15th, 2006, 10:26 PM
#11
-
Feb 15th, 2006, 10:30 PM
#12
Re: Identifying a network drive and finding its path
Gig, stop biting your tongue 
It was a good sugestion, .Net and legacy VB is very close (it almost scares you). Give his suggestion a legit try, don't pass it off. I find myself doing that alot, thinking VB6 people can't help me (not that he is), but they can... MS made it really easy to transition so it's very common to get legacy and .Net development confused.
-
Feb 15th, 2006, 10:33 PM
#13
Re: Identifying a network drive and finding its path
Also should be obvious when I mention "add a reference to System.Management"... and I have never been a VB6 programmer
-
Feb 15th, 2006, 10:37 PM
#14
Thread Starter
Addicted Member
Re: Identifying a network drive and finding its path
 Originally Posted by gigemboy
lol Of course its VB.NET silly  Worked fine on my machine. The managementobject doesnt have that property.. its all part of the WMI OBJECT RETURNED for the WMI Class you specify... try the code out first before you think it doesnt work
***EDIT - also look above, I edited my post with the property that should show the network drive path
P.S. I also don't like being told "thanks for the effort" when it should do exactly what you stated 
It works fine, thanks. I wasn't sure because the quote tag about your code said "visual basic code" rather than .NET code (and the bit at the bottom says assume all code is .NET unless stated otherwise). I also always use Msgbox rather than MessageBox - on top of it all, I never did much programming in VB6 so I'm not always sure what to look for.
Thanks for the help.
-
Feb 15th, 2006, 10:38 PM
#15
Re: [RESOLVED] Identifying a network drive and finding its path
hehe no prob. Messagebox.Show is actually more correct to use in .NET. MsgBox is a runtime function carried over from VB6.
(and the "visual basic code" is put in by the forum software when you use the vbcode tags)
Last edited by gigemboy; Feb 15th, 2006 at 10:43 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|