Copy and Paste Files to and from the Clipboard

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DraguVaso

    #1

    Copy and Paste Files to and from the Clipboard

    Hi,

    I'm looking for a way to Copy and Paste Files to the clipboard.
    I found a lot of articles to copy pieces of text and bitmaps etc, but nog
    whole files.

    Whay I need is like you have in windows explorer: when you do a right-click
    on a file and choose Copy, and than paste it somewhere in my application and
    vice versa.

    Anybody knows how to do this?

    Thanks in advance,

    Pieter


  • Cor

    #2
    Re: Copy and Paste Files to and from the Clipboard

    Hi Pieter,

    The place with information

    http://msdn.microsoft.com/library/en...ardSupport.asp

    And a sample from a paste

    I hope this helps

    Cor

    \\\
    'Copy with windows explore some files and than this
    Private Sub Button1_Click(B yVal sender _
    As Object, ByVal e As System.EventArg s) Handles Button1.Click
    Dim folderbrowserDi alog1 As New FolderBrowserDi alog
    Dim iData As IDataObject = Clipboard.GetDa taObject()
    If iData.GetDataPr esent(DataForma ts.FileDrop) Then
    Dim clipbrd As String() = DirectCast(iDat a.GetData(DataF ormats.FileDrop ),
    String())
    Dim i As Integer
    folderbrowserDi alog1.ShowDialo g()
    For i = 0 To clipbrd.Length - 1
    If System.IO.File. Exists(folderbr owserDialog1.Se lectedPath _
    & System.IO.Path. GetFileName(cli pbrd(i))) Then
    System.IO.File. Move(folderbrow serDialog1.Sele ctedPath & _
    "\" & _
    System.IO.Path. GetFileName(cli pbrd(i)), _
    folderbrowserDi alog1.SelectedP ath & "temptemptemp.t emp")
    End If
    System.IO.File. Copy(clipbrd(i) , folderbrowserDi alog1.SelectedP ath & _
    "\" & _
    System.IO.Path. GetFileName(cli pbrd(i)))
    If System.IO.File. Exists(folderbr owserDialog1.Se lectedPath _
    & "temptemptemp.t emp") Then
    System.IO.File. Delete(folderbr owserDialog1.Se lectedPath & _
    "temptemptemp.t emp")
    End If
    Next
    End If
    End Sub
    ///

    [color=blue]
    > I'm looking for a way to Copy and Paste Files to the clipboard.
    > I found a lot of articles to copy pieces of text and bitmaps etc, but nog
    > whole files.
    >
    > Whay I need is like you have in windows explorer: when you do a[/color]
    right-click[color=blue]
    > on a file and choose Copy, and than paste it somewhere in my application[/color]
    and[color=blue]
    > vice versa.
    >
    > Anybody knows how to do this?
    >
    > Thanks in advance,
    >
    > Pieter
    >
    >[/color]


    Comment

    • DraguVaso

      #3
      Re: Copy and Paste Files to and from the Clipboard

      Thanks a lot, the pasting is working.
      Unfortunately I'm not able to copy a file to the clipboard. any idea?

      "Cor" <non@non.com> wrote in message
      news:#F#TK1B3DH A.2408@tk2msftn gp13.phx.gbl...[color=blue]
      > Hi Pieter,
      >
      > The place with information
      >
      >[/color]
      http://msdn.microsoft.com/library/en...opClipboardSup
      port.asp[color=blue]
      >
      > And a sample from a paste
      >
      > I hope this helps
      >
      > Cor
      >
      > \\\
      > 'Copy with windows explore some files and than this
      > Private Sub Button1_Click(B yVal sender _
      > As Object, ByVal e As System.EventArg s) Handles Button1.Click
      > Dim folderbrowserDi alog1 As New FolderBrowserDi alog
      > Dim iData As IDataObject = Clipboard.GetDa taObject()
      > If iData.GetDataPr esent(DataForma ts.FileDrop) Then
      > Dim clipbrd As String() = DirectCast(iDat a.GetData(DataF ormats.FileDrop ),
      > String())
      > Dim i As Integer
      > folderbrowserDi alog1.ShowDialo g()
      > For i = 0 To clipbrd.Length - 1
      > If System.IO.File. Exists(folderbr owserDialog1.Se lectedPath _
      > & System.IO.Path. GetFileName(cli pbrd(i))) Then
      > System.IO.File. Move(folderbrow serDialog1.Sele ctedPath & _
      > "\" & _
      > System.IO.Path. GetFileName(cli pbrd(i)), _
      > folderbrowserDi alog1.SelectedP ath & "temptemptemp.t emp")
      > End If
      > System.IO.File. Copy(clipbrd(i) , folderbrowserDi alog1.SelectedP ath & _
      > "\" & _
      > System.IO.Path. GetFileName(cli pbrd(i)))
      > If System.IO.File. Exists(folderbr owserDialog1.Se lectedPath _
      > & "temptemptemp.t emp") Then
      > System.IO.File. Delete(folderbr owserDialog1.Se lectedPath & _
      > "temptemptemp.t emp")
      > End If
      > Next
      > End If
      > End Sub
      > ///
      >
      >[color=green]
      > > I'm looking for a way to Copy and Paste Files to the clipboard.
      > > I found a lot of articles to copy pieces of text and bitmaps etc, but[/color][/color]
      nog[color=blue][color=green]
      > > whole files.
      > >
      > > Whay I need is like you have in windows explorer: when you do a[/color]
      > right-click[color=green]
      > > on a file and choose Copy, and than paste it somewhere in my application[/color]
      > and[color=green]
      > > vice versa.
      > >
      > > Anybody knows how to do this?
      > >
      > > Thanks in advance,
      > >
      > > Pieter
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Iouri

        #4
        Re: Copy and Paste Files to and from the Clipboard

        The following code can be used to place file data on the clipboard (it will
        not just be the name, nor will it be
        the contents of the file). The "DataFormat s" parameter controls how other
        applications deal with the
        clipboard data. The file(s) to be copied must be placed on the clipboard as
        an array of strings...

        (VB.NET)
        Dim DataObject As New DataObject()
        Dim file(0) As String
        file(0) = "C:\Test.tx t"
        DataObject.SetD ata(DataFormats .FileDrop, True, file)
        Clipboard.SetDa taObject(DataOb ject)

        "DraguVaso" <pietercoucke@h otmail.com> wrote in message
        news:4007ed29$0 $297$ba620e4c@n ews.skynet.be.. .[color=blue]
        > Thanks a lot, the pasting is working.
        > Unfortunately I'm not able to copy a file to the clipboard. any idea?
        >
        > "Cor" <non@non.com> wrote in message
        > news:#F#TK1B3DH A.2408@tk2msftn gp13.phx.gbl...[color=green]
        > > Hi Pieter,
        > >
        > > The place with information
        > >
        > >[/color]
        >[/color]
        http://msdn.microsoft.com/library/en...opClipboardSup[color=blue]
        > port.asp[color=green]
        > >
        > > And a sample from a paste
        > >
        > > I hope this helps
        > >
        > > Cor
        > >
        > > \\\
        > > 'Copy with windows explore some files and than this
        > > Private Sub Button1_Click(B yVal sender _
        > > As Object, ByVal e As System.EventArg s) Handles Button1.Click
        > > Dim folderbrowserDi alog1 As New FolderBrowserDi alog
        > > Dim iData As IDataObject = Clipboard.GetDa taObject()
        > > If iData.GetDataPr esent(DataForma ts.FileDrop) Then
        > > Dim clipbrd As String() =[/color][/color]
        DirectCast(iDat a.GetData(DataF ormats.FileDrop ),[color=blue][color=green]
        > > String())
        > > Dim i As Integer
        > > folderbrowserDi alog1.ShowDialo g()
        > > For i = 0 To clipbrd.Length - 1
        > > If System.IO.File. Exists(folderbr owserDialog1.Se lectedPath _
        > > & System.IO.Path. GetFileName(cli pbrd(i))) Then
        > > System.IO.File. Move(folderbrow serDialog1.Sele ctedPath & _
        > > "\" & _
        > > System.IO.Path. GetFileName(cli pbrd(i)), _
        > > folderbrowserDi alog1.SelectedP ath & "temptemptemp.t emp")
        > > End If
        > > System.IO.File. Copy(clipbrd(i) , folderbrowserDi alog1.SelectedP ath & _
        > > "\" & _
        > > System.IO.Path. GetFileName(cli pbrd(i)))
        > > If System.IO.File. Exists(folderbr owserDialog1.Se lectedPath _
        > > & "temptemptemp.t emp") Then
        > > System.IO.File. Delete(folderbr owserDialog1.Se lectedPath & _
        > > "temptemptemp.t emp")
        > > End If
        > > Next
        > > End If
        > > End Sub
        > > ///
        > >
        > >[color=darkred]
        > > > I'm looking for a way to Copy and Paste Files to the clipboard.
        > > > I found a lot of articles to copy pieces of text and bitmaps etc, but[/color][/color]
        > nog[color=green][color=darkred]
        > > > whole files.
        > > >
        > > > Whay I need is like you have in windows explorer: when you do a[/color]
        > > right-click[color=darkred]
        > > > on a file and choose Copy, and than paste it somewhere in my[/color][/color][/color]
        application[color=blue][color=green]
        > > and[color=darkred]
        > > > vice versa.
        > > >
        > > > Anybody knows how to do this?
        > > >
        > > > Thanks in advance,
        > > >
        > > > Pieter
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • 100

          #5
          Re: Copy and Paste Files to and from the Clipboard

          Hi DraguVaso,
          When drag-and-drop or copies files to the clipboard windows explorer doesn't
          drag or copy the entire file to the clipboard. It just move a structure of
          data called DROPFILES which carry path names of the files you want to move
          or copy as well as flag whether these strings are in UNICODE or ANSI and the
          point on the screen where the drag begun. The clipboard uses the same
          structure but the point field is not used.

          However thanks to the .net framework and DataObject class placing that
          structure in the clipboard is as easy as creating array of strings, puting
          the array in a data object and put the data object in the clipboard.

          the following is a code that do this:

          Clipboard.SetDa taObject(new DataObject(Data Formats.FileDro p, new
          string[]{"C:\\Temp\\Tes tFile.txt"}));

          HTH
          B\rgds
          100

          "DraguVaso" <pietercoucke@h otmail.com> wrote in message
          news:4007ed29$0 $297$ba620e4c@n ews.skynet.be.. .[color=blue]
          > Thanks a lot, the pasting is working.
          > Unfortunately I'm not able to copy a file to the clipboard. any idea?
          >
          > "Cor" <non@non.com> wrote in message
          > news:#F#TK1B3DH A.2408@tk2msftn gp13.phx.gbl...[color=green]
          > > Hi Pieter,
          > >
          > > The place with information
          > >
          > >[/color]
          >[/color]
          http://msdn.microsoft.com/library/en...opClipboardSup[color=blue]
          > port.asp[color=green]
          > >
          > > And a sample from a paste
          > >
          > > I hope this helps
          > >
          > > Cor
          > >
          > > \\\
          > > 'Copy with windows explore some files and than this
          > > Private Sub Button1_Click(B yVal sender _
          > > As Object, ByVal e As System.EventArg s) Handles Button1.Click
          > > Dim folderbrowserDi alog1 As New FolderBrowserDi alog
          > > Dim iData As IDataObject = Clipboard.GetDa taObject()
          > > If iData.GetDataPr esent(DataForma ts.FileDrop) Then
          > > Dim clipbrd As String() =[/color][/color]
          DirectCast(iDat a.GetData(DataF ormats.FileDrop ),[color=blue][color=green]
          > > String())
          > > Dim i As Integer
          > > folderbrowserDi alog1.ShowDialo g()
          > > For i = 0 To clipbrd.Length - 1
          > > If System.IO.File. Exists(folderbr owserDialog1.Se lectedPath _
          > > & System.IO.Path. GetFileName(cli pbrd(i))) Then
          > > System.IO.File. Move(folderbrow serDialog1.Sele ctedPath & _
          > > "\" & _
          > > System.IO.Path. GetFileName(cli pbrd(i)), _
          > > folderbrowserDi alog1.SelectedP ath & "temptemptemp.t emp")
          > > End If
          > > System.IO.File. Copy(clipbrd(i) , folderbrowserDi alog1.SelectedP ath & _
          > > "\" & _
          > > System.IO.Path. GetFileName(cli pbrd(i)))
          > > If System.IO.File. Exists(folderbr owserDialog1.Se lectedPath _
          > > & "temptemptemp.t emp") Then
          > > System.IO.File. Delete(folderbr owserDialog1.Se lectedPath & _
          > > "temptemptemp.t emp")
          > > End If
          > > Next
          > > End If
          > > End Sub
          > > ///
          > >
          > >[color=darkred]
          > > > I'm looking for a way to Copy and Paste Files to the clipboard.
          > > > I found a lot of articles to copy pieces of text and bitmaps etc, but[/color][/color]
          > nog[color=green][color=darkred]
          > > > whole files.
          > > >
          > > > Whay I need is like you have in windows explorer: when you do a[/color]
          > > right-click[color=darkred]
          > > > on a file and choose Copy, and than paste it somewhere in my[/color][/color][/color]
          application[color=blue][color=green]
          > > and[color=darkred]
          > > > vice versa.
          > > >
          > > > Anybody knows how to do this?
          > > >
          > > > Thanks in advance,
          > > >
          > > > Pieter
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • DraguVaso

            #6
            Re: Copy and Paste Files to and from the Clipboard

            Thanks louri and 100! it worked fine!

            "100" <100@100.com> wrote in message
            news:OcR$8lF3DH A.1804@TK2MSFTN GP12.phx.gbl...[color=blue]
            > Hi DraguVaso,
            > When drag-and-drop or copies files to the clipboard windows explorer[/color]
            doesn't[color=blue]
            > drag or copy the entire file to the clipboard. It just move a structure of
            > data called DROPFILES which carry path names of the files you want to move
            > or copy as well as flag whether these strings are in UNICODE or ANSI and[/color]
            the[color=blue]
            > point on the screen where the drag begun. The clipboard uses the same
            > structure but the point field is not used.
            >
            > However thanks to the .net framework and DataObject class placing that
            > structure in the clipboard is as easy as creating array of strings, puting
            > the array in a data object and put the data object in the clipboard.
            >
            > the following is a code that do this:
            >
            > Clipboard.SetDa taObject(new DataObject(Data Formats.FileDro p, new
            > string[]{"C:\\Temp\\Tes tFile.txt"}));
            >
            > HTH
            > B\rgds
            > 100
            >
            > "DraguVaso" <pietercoucke@h otmail.com> wrote in message
            > news:4007ed29$0 $297$ba620e4c@n ews.skynet.be.. .[color=green]
            > > Thanks a lot, the pasting is working.
            > > Unfortunately I'm not able to copy a file to the clipboard. any idea?
            > >
            > > "Cor" <non@non.com> wrote in message
            > > news:#F#TK1B3DH A.2408@tk2msftn gp13.phx.gbl...[color=darkred]
            > > > Hi Pieter,
            > > >
            > > > The place with information
            > > >
            > > >[/color]
            > >[/color]
            >[/color]
            http://msdn.microsoft.com/library/en...opClipboardSup[color=blue][color=green]
            > > port.asp[color=darkred]
            > > >
            > > > And a sample from a paste
            > > >
            > > > I hope this helps
            > > >
            > > > Cor
            > > >
            > > > \\\
            > > > 'Copy with windows explore some files and than this
            > > > Private Sub Button1_Click(B yVal sender _
            > > > As Object, ByVal e As System.EventArg s) Handles Button1.Click
            > > > Dim folderbrowserDi alog1 As New FolderBrowserDi alog
            > > > Dim iData As IDataObject = Clipboard.GetDa taObject()
            > > > If iData.GetDataPr esent(DataForma ts.FileDrop) Then
            > > > Dim clipbrd As String() =[/color][/color]
            > DirectCast(iDat a.GetData(DataF ormats.FileDrop ),[color=green][color=darkred]
            > > > String())
            > > > Dim i As Integer
            > > > folderbrowserDi alog1.ShowDialo g()
            > > > For i = 0 To clipbrd.Length - 1
            > > > If System.IO.File. Exists(folderbr owserDialog1.Se lectedPath _
            > > > & System.IO.Path. GetFileName(cli pbrd(i))) Then
            > > > System.IO.File. Move(folderbrow serDialog1.Sele ctedPath & _
            > > > "\" & _
            > > > System.IO.Path. GetFileName(cli pbrd(i)), _
            > > > folderbrowserDi alog1.SelectedP ath & "temptemptemp.t emp")
            > > > End If
            > > > System.IO.File. Copy(clipbrd(i) , folderbrowserDi alog1.SelectedP ath & _
            > > > "\" & _
            > > > System.IO.Path. GetFileName(cli pbrd(i)))
            > > > If System.IO.File. Exists(folderbr owserDialog1.Se lectedPath _
            > > > & "temptemptemp.t emp") Then
            > > > System.IO.File. Delete(folderbr owserDialog1.Se lectedPath & _
            > > > "temptemptemp.t emp")
            > > > End If
            > > > Next
            > > > End If
            > > > End Sub
            > > > ///
            > > >
            > > >
            > > > > I'm looking for a way to Copy and Paste Files to the clipboard.
            > > > > I found a lot of articles to copy pieces of text and bitmaps etc,[/color][/color][/color]
            but[color=blue][color=green]
            > > nog[color=darkred]
            > > > > whole files.
            > > > >
            > > > > Whay I need is like you have in windows explorer: when you do a
            > > > right-click
            > > > > on a file and choose Copy, and than paste it somewhere in my[/color][/color]
            > application[color=green][color=darkred]
            > > > and
            > > > > vice versa.
            > > > >
            > > > > Anybody knows how to do this?
            > > > >
            > > > > Thanks in advance,
            > > > >
            > > > > Pieter
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...