Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Converting full path to URI

Converting full path to URI

Scheduled Pinned Locked Moved Visual Basic
helpcode-review
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    egottwald
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • E egottwald

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      E 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        E Offline
        E Offline
        egottwald
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • E egottwald

          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

          J Offline
          J Offline
          Jon_Boy
          wrote on last edited by
          #4

          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.

          E 1 Reply Last reply
          0
          • J Jon_Boy

            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.

            E Offline
            E Offline
            egottwald
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • E egottwald

              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

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups