|
-
Mar 10th, 2006, 10:40 AM
#1
UNC to regular path (not the other way!)
Umm i had another post like this, seems like people still didnt understand what I want
I want to convert a UNC path back to a windows path with drive letters in it. How would i do it?
ie, i want to convert \\server\share to "d:" if that share is mapped to drive D on the local computer
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Mar 10th, 2006, 11:29 AM
#2
Re: UNC to regular path (not the other way!)
MrPolite, that was exactly what the example I posted for you did 
what about it didn't do what you were saying? you type in a UNC path in the textbox, and the code will look at all your drive letters to see if one matches that UNC, and gives you the drive letter of the match, if present...
-
Mar 10th, 2006, 11:42 AM
#3
Re: UNC to regular path (not the other way!)
Have you tried FileSystemObject.
Probabaly, this function is what you are looking for.
VB Code:
Private Function convertUNCToDrive(ByVal pathName As String) As String
Dim fileSystem As New FileSystemObjectClass
Dim pathToReturn As String
'loop through all drives
For Each drv As Drive In fileSystem.Drives
'check if the drive is mapped
If drv.DriveType = DriveTypeConst.Remote Then
'check if the share is same as the path mentioned
If pathName.Substring(0, drv.ShareName.Length) = drv.ShareName.ToString Then
'replace it with drive letter
pathToReturn = pathName.Replace(drv.ShareName, drv.Path)
Exit For
End If
End If
Next
Return pathToReturn
End Function
Add a reference to Microsoft Scripting Runtime. And put Imports Scripting at the top.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Mar 10th, 2006, 12:51 PM
#4
Re: UNC to regular path (not the other way!)
The wmi sample I had mentioned would do it as well, you would loop all instances of the Win32_LogicalDisk WMI class, see if the "DriveType" property is "4" (meaning Network Drive), then see if the "ProviderName" property (which is the property that lists the network drive UNC path) equals the UNC path you have, then the drive letter is the "name" property of the same object...
I could do a sample that does this if you really need it, but it seems that you have several examples that might work as well...
Last edited by gigemboy; Mar 10th, 2006 at 12:56 PM.
-
Mar 10th, 2006, 01:19 PM
#5
Re: UNC to regular path (not the other way!)
 Originally Posted by kleinma
MrPolite, that was exactly what the example I posted for you did
what about it didn't do what you were saying? you type in a UNC path in the textbox, and the code will look at all your drive letters to see if one matches that UNC, and gives you the drive letter of the match, if present...
oooooooh sorry
i dont have visual studio.net.... i was just looking at the API call and judging by what that API call does i thought it's doign the opposite of what i wanted
okay it's a start... now i guess i should ask the rest in a different forum. Thanks for the solutions guys. I;m doing this in C++ so i should use APIs only not .NET....
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Mar 10th, 2006, 01:44 PM
#6
Re: UNC to regular path (not the other way!)
you may struggle the api way, you can sometimes get the GetLongPathName api to work, but it can raise issues over server privilages.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
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
|