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. Is it possible to copy a file to a destination that includes a shortcut?

Is it possible to copy a file to a destination that includes a shortcut?

Scheduled Pinned Locked Moved Visual Basic
questionvisual-studiosysadminxmlhelp
4 Posts 2 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.
  • J Offline
    J Offline
    Jon_Boy
    wrote on last edited by
    #1

    Is it possible to copy a file to a destination that includes a shortcut link in the path? For example, below the \Staged\ is actually Staged.LNK that points to a diff. server. I normally would use the UNC path but am being asked to do this specifically. User has full rights on the directory as well. 'Statement fails. System.IO.File.Copy("\\Server\Data Dumps\86355 - Shipment Notice Detail 07.18.2011 11.15.15.108.xml", "C:\Documents and Settings\John Doe\Desktop\Staged\86355 - Shipment Notice Detail 07.18.2011 11.15.15.108.xml") 'If I add-in Staged.LNK, the statement fails, without .LNK, VB creates an actual folder called Staged and copies the file into that folder vs. using the shortcut path (to a diff. server). My.Computer.FileSystem.CopyFile("\\Server\Data Dumps\86355 - Shipment Notice Detail 07.18.2011 11.15.15.108.xml", "C:\Documents and Settings\John Doe\Desktop\Staged\86355 - Shipment Notice Detail 07.18.2011 11.15.15.108.xml") Thanks for any help or comments.

    "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

    L 1 Reply Last reply
    0
    • J Jon_Boy

      Is it possible to copy a file to a destination that includes a shortcut link in the path? For example, below the \Staged\ is actually Staged.LNK that points to a diff. server. I normally would use the UNC path but am being asked to do this specifically. User has full rights on the directory as well. 'Statement fails. System.IO.File.Copy("\\Server\Data Dumps\86355 - Shipment Notice Detail 07.18.2011 11.15.15.108.xml", "C:\Documents and Settings\John Doe\Desktop\Staged\86355 - Shipment Notice Detail 07.18.2011 11.15.15.108.xml") 'If I add-in Staged.LNK, the statement fails, without .LNK, VB creates an actual folder called Staged and copies the file into that folder vs. using the shortcut path (to a diff. server). My.Computer.FileSystem.CopyFile("\\Server\Data Dumps\86355 - Shipment Notice Detail 07.18.2011 11.15.15.108.xml", "C:\Documents and Settings\John Doe\Desktop\Staged\86355 - Shipment Notice Detail 07.18.2011 11.15.15.108.xml") Thanks for any help or comments.

      "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Jon_Boy wrote:

      Is it possible to copy a file to a destination that includes a shortcut link in the path?

      No, since the .lnk is a file, not a virtual path. The file-system treats it as a file, not as a NTFS Junction Point[^]. As an alternative, you can use VB.NET to read what the .lnk file is pointing to, and concatenate that to your path. You'd need to import a COM-library called "Windows Script Host Object Model", then you could run code similar to this;

      Imports IWshRuntimeLibrary

      Module ShortcutExample
      Sub Main
      Dim MyWshShell = new WshShell()
      Dim MyShortcut = MyWshShell.CreateShortcut("C:\Users\Eddy\Desktop\SomeFolder.lnk")
      Console.WriteLine(MyShortcut.TargetPath)
      Console.ReadKey()
      End Sub
      End Module

      Happy Programming :)

      Bastard Programmer from Hell :suss:

      J 1 Reply Last reply
      0
      • L Lost User

        Jon_Boy wrote:

        Is it possible to copy a file to a destination that includes a shortcut link in the path?

        No, since the .lnk is a file, not a virtual path. The file-system treats it as a file, not as a NTFS Junction Point[^]. As an alternative, you can use VB.NET to read what the .lnk file is pointing to, and concatenate that to your path. You'd need to import a COM-library called "Windows Script Host Object Model", then you could run code similar to this;

        Imports IWshRuntimeLibrary

        Module ShortcutExample
        Sub Main
        Dim MyWshShell = new WshShell()
        Dim MyShortcut = MyWshShell.CreateShortcut("C:\Users\Eddy\Desktop\SomeFolder.lnk")
        Console.WriteLine(MyShortcut.TargetPath)
        Console.ReadKey()
        End Sub
        End Module

        Happy Programming :)

        Bastard Programmer from Hell :suss:

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

        Sounds like a plan. Thanks!

        "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

        L 1 Reply Last reply
        0
        • J Jon_Boy

          Sounds like a plan. Thanks!

          "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You're welcome :)

          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