Converting full path to URI
-
I'm writing a little app to save the clipboard to a file and then mail a link to it to selected recipients. For the saved file to be accessible by the recipients, I verify that the parent folder is shared. However, if the share is on a local drive, I have to convert the full path to something like: DriveID:\SomePath1\SharedFolderName\SomePath2\FileName.ext and then to: \\HostDNSname\ShareName\SomePath2\FileName.ext where ShareName is the provider name for: DriveID:\SomePath1\SharedFolderName and SharedFolderName is the 'deepest' level share - i.e., it accounts for the possibility of SomePath1 including higher level shared folders. I'm using the Win32_LogicalDisk ManagementClass and Win32_Share ManagementClass to obtain the info I need, but have not found an easy way to do the path conversion. Before I dig into the implementation, I thought I'd check to see whether anyone has attempted this and whether they found an easy way to do this. Comments would be appreciated...
emilG "Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve." - Alan Perlis
-
I'm writing a little app to save the clipboard to a file and then mail a link to it to selected recipients. For the saved file to be accessible by the recipients, I verify that the parent folder is shared. However, if the share is on a local drive, I have to convert the full path to something like: DriveID:\SomePath1\SharedFolderName\SomePath2\FileName.ext and then to: \\HostDNSname\ShareName\SomePath2\FileName.ext where ShareName is the provider name for: DriveID:\SomePath1\SharedFolderName and SharedFolderName is the 'deepest' level share - i.e., it accounts for the possibility of SomePath1 including higher level shared folders. I'm using the Win32_LogicalDisk ManagementClass and Win32_Share ManagementClass to obtain the info I need, but have not found an easy way to do the path conversion. Before I dig into the implementation, I thought I'd check to see whether anyone has attempted this and whether they found an easy way to do this. Comments would be appreciated...
emilG "Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve." - Alan Perlis
What's so hard about removing the beginning of a string and replacing it with a workstation name?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
What's so hard about removing the beginning of a string and replacing it with a workstation name?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Nothing hard, once I have the string. For instance, if I have the following shares on my machine: D:\ with a share name of "D$" and: D:\MyPrivateDownloads\Tools\ABCtool\ with a share name of "ABCdownload" plus a bunch of other shares on the same drive, with the file stored in: D:\MyPrivateDownloads\Tools\ABCtool\Docs\UserManual\UsingABCinfo.pdf I want to send the following link: \\myMachineName\ABCdownload\Docs\UserManual\UsingABCinfo.pdf and not: \\myMachineName\D$\MyPrivateDownloads\Tools\ABCtool\Docs\UserManual\UsingABCinfo.pdf So, although it is not rocket science to accomplish this, I was wondering if there was an easy way of accomplishing it [via some framework class maybe].
emilG "Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve." - Alan Perlis
-
Nothing hard, once I have the string. For instance, if I have the following shares on my machine: D:\ with a share name of "D$" and: D:\MyPrivateDownloads\Tools\ABCtool\ with a share name of "ABCdownload" plus a bunch of other shares on the same drive, with the file stored in: D:\MyPrivateDownloads\Tools\ABCtool\Docs\UserManual\UsingABCinfo.pdf I want to send the following link: \\myMachineName\ABCdownload\Docs\UserManual\UsingABCinfo.pdf and not: \\myMachineName\D$\MyPrivateDownloads\Tools\ABCtool\Docs\UserManual\UsingABCinfo.pdf So, although it is not rocket science to accomplish this, I was wondering if there was an easy way of accomplishing it [via some framework class maybe].
emilG "Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve." - Alan Perlis
1. Dave is right on this. You're making this to difficult. Do something like:
replace("D:\MyPrivateDownloads\Tools\ABCtool\Docs\UserManual\UsingABCinfo.pdf","D:\MyPrivateDownloads\Tools", "\\" & environment.GetEnvironmentVariable("ComputerName"))
Keep it simple.
egottwald wrote:
D:\ with a share name of "D$"
2. C$ and D$ are admin shares and shouldn't be used. If it were me, I'd disable them entirely because someone could just access all the dirs/files regardless of what you intended (with \\myMachineName\D$).
Any suggestions, ideas, or 'constructive criticism' are always welcome.
-
1. Dave is right on this. You're making this to difficult. Do something like:
replace("D:\MyPrivateDownloads\Tools\ABCtool\Docs\UserManual\UsingABCinfo.pdf","D:\MyPrivateDownloads\Tools", "\\" & environment.GetEnvironmentVariable("ComputerName"))
Keep it simple.
egottwald wrote:
D:\ with a share name of "D$"
2. C$ and D$ are admin shares and shouldn't be used. If it were me, I'd disable them entirely because someone could just access all the dirs/files regardless of what you intended (with \\myMachineName\D$).
Any suggestions, ideas, or 'constructive criticism' are always welcome.
1. You're making it too simple. The string replace is trivial when the strings are known. In an app, they are both dynamic, and what I'm ideally looking for is something like:
strSavedFileFullPath = GetSavedFileLocation() ' <<< This is not a problem If IsLocalShare(strSavedFileFullPath) Then ' <<< This is not a problem either strLinktoSend = ConvertFullPathToClickableLink(strSavedFileFullPath) End If
I know how to code ConvertFullPathToClickableLink, but is there an API I can use instead? 2. I used D$ as an example...emilG "Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve." - Alan Perlis
-
1. You're making it too simple. The string replace is trivial when the strings are known. In an app, they are both dynamic, and what I'm ideally looking for is something like:
strSavedFileFullPath = GetSavedFileLocation() ' <<< This is not a problem If IsLocalShare(strSavedFileFullPath) Then ' <<< This is not a problem either strLinktoSend = ConvertFullPathToClickableLink(strSavedFileFullPath) End If
I know how to code ConvertFullPathToClickableLink, but is there an API I can use instead? 2. I used D$ as an example...emilG "Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve." - Alan Perlis
egottwald wrote:
but is there an API I can use instead
Not in the .NET Framework, no. Typically, I wouldn't be sharing stuff from individual users machines. They'd be forced to post stuff on a central temp drive, that I wipe out every night, and link to that. In your situation, there are too many unknowns, so force one to be a known. In your example, it sounds like your code can either create a subfolder under a known share, or can create a share for a known folder. This is, to say the least, an administrative nightmare.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008