472,328 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

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
Nov 20 '05 #1
5 20685
Cor
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(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folderbrowserDialog1 As New FolderBrowserDialog
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.FileDrop) Then
Dim clipbrd As String() = DirectCast(iData.GetData(DataFormats.FileDrop),
String())
Dim i As Integer
folderbrowserDialog1.ShowDialog()
For i = 0 To clipbrd.Length - 1
If System.IO.File.Exists(folderbrowserDialog1.Selecte dPath _
& System.IO.Path.GetFileName(clipbrd(i))) Then
System.IO.File.Move(folderbrowserDialog1.SelectedP ath & _
"\" & _
System.IO.Path.GetFileName(clipbrd(i)), _
folderbrowserDialog1.SelectedPath & "temptemptemp.temp")
End If
System.IO.File.Copy(clipbrd(i), folderbrowserDialog1.SelectedPath & _
"\" & _
System.IO.Path.GetFileName(clipbrd(i)))
If System.IO.File.Exists(folderbrowserDialog1.Selecte dPath _
& "temptemptemp.temp") Then
System.IO.File.Delete(folderbrowserDialog1.Selecte dPath & _
"temptemptemp.temp")
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, 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

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

"Cor" <no*@non.com> wrote in message
news:#F**************@tk2msftngp13.phx.gbl...
Hi Pieter,

The place with information

http://msdn.microsoft.com/library/en...opClipboardSup
port.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(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folderbrowserDialog1 As New FolderBrowserDialog
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.FileDrop) Then
Dim clipbrd As String() = DirectCast(iData.GetData(DataFormats.FileDrop),
String())
Dim i As Integer
folderbrowserDialog1.ShowDialog()
For i = 0 To clipbrd.Length - 1
If System.IO.File.Exists(folderbrowserDialog1.Selecte dPath _
& System.IO.Path.GetFileName(clipbrd(i))) Then
System.IO.File.Move(folderbrowserDialog1.SelectedP ath & _
"\" & _
System.IO.Path.GetFileName(clipbrd(i)), _
folderbrowserDialog1.SelectedPath & "temptemptemp.temp")
End If
System.IO.File.Copy(clipbrd(i), folderbrowserDialog1.SelectedPath & _
"\" & _
System.IO.Path.GetFileName(clipbrd(i)))
If System.IO.File.Exists(folderbrowserDialog1.Selecte dPath _
& "temptemptemp.temp") Then
System.IO.File.Delete(folderbrowserDialog1.Selecte dPath & _
"temptemptemp.temp")
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, 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


Nov 20 '05 #3
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 "DataFormats" 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.txt"
DataObject.SetData(DataFormats.FileDrop, True, file)
Clipboard.SetDataObject(DataObject)

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:40*********************@news.skynet.be...
Thanks a lot, the pasting is working.
Unfortunately I'm not able to copy a file to the clipboard. any idea?

"Cor" <no*@non.com> wrote in message
news:#F**************@tk2msftngp13.phx.gbl...
Hi Pieter,

The place with information

http://msdn.microsoft.com/library/en...opClipboardSup port.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(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folderbrowserDialog1 As New FolderBrowserDialog
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.FileDrop) Then
Dim clipbrd As String() = DirectCast(iData.GetData(DataFormats.FileDrop),
String())
Dim i As Integer
folderbrowserDialog1.ShowDialog()
For i = 0 To clipbrd.Length - 1
If System.IO.File.Exists(folderbrowserDialog1.Selecte dPath _
& System.IO.Path.GetFileName(clipbrd(i))) Then
System.IO.File.Move(folderbrowserDialog1.SelectedP ath & _
"\" & _
System.IO.Path.GetFileName(clipbrd(i)), _
folderbrowserDialog1.SelectedPath & "temptemptemp.temp")
End If
System.IO.File.Copy(clipbrd(i), folderbrowserDialog1.SelectedPath & _
"\" & _
System.IO.Path.GetFileName(clipbrd(i)))
If System.IO.File.Exists(folderbrowserDialog1.Selecte dPath _
& "temptemptemp.temp") Then
System.IO.File.Delete(folderbrowserDialog1.Selecte dPath & _
"temptemptemp.temp")
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, 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



Nov 20 '05 #4
100
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.SetDataObject(new DataObject(DataFormats.FileDrop, new
string[]{"C:\\Temp\\TestFile.txt"}));

HTH
B\rgds
100

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:40*********************@news.skynet.be...
Thanks a lot, the pasting is working.
Unfortunately I'm not able to copy a file to the clipboard. any idea?

"Cor" <no*@non.com> wrote in message
news:#F**************@tk2msftngp13.phx.gbl...
Hi Pieter,

The place with information

http://msdn.microsoft.com/library/en...opClipboardSup port.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(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folderbrowserDialog1 As New FolderBrowserDialog
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.FileDrop) Then
Dim clipbrd As String() = DirectCast(iData.GetData(DataFormats.FileDrop),
String())
Dim i As Integer
folderbrowserDialog1.ShowDialog()
For i = 0 To clipbrd.Length - 1
If System.IO.File.Exists(folderbrowserDialog1.Selecte dPath _
& System.IO.Path.GetFileName(clipbrd(i))) Then
System.IO.File.Move(folderbrowserDialog1.SelectedP ath & _
"\" & _
System.IO.Path.GetFileName(clipbrd(i)), _
folderbrowserDialog1.SelectedPath & "temptemptemp.temp")
End If
System.IO.File.Copy(clipbrd(i), folderbrowserDialog1.SelectedPath & _
"\" & _
System.IO.Path.GetFileName(clipbrd(i)))
If System.IO.File.Exists(folderbrowserDialog1.Selecte dPath _
& "temptemptemp.temp") Then
System.IO.File.Delete(folderbrowserDialog1.Selecte dPath & _
"temptemptemp.temp")
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, 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



Nov 20 '05 #5
Thanks louri and 100! it worked fine!

"100" <10*@100.com> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
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.SetDataObject(new DataObject(DataFormats.FileDrop, new
string[]{"C:\\Temp\\TestFile.txt"}));

HTH
B\rgds
100

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:40*********************@news.skynet.be...
Thanks a lot, the pasting is working.
Unfortunately I'm not able to copy a file to the clipboard. any idea?

"Cor" <no*@non.com> wrote in message
news:#F**************@tk2msftngp13.phx.gbl...
Hi Pieter,

The place with information

http://msdn.microsoft.com/library/en...opClipboardSup
port.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(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folderbrowserDialog1 As New FolderBrowserDialog
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.FileDrop) Then
Dim clipbrd As String() = DirectCast(iData.GetData(DataFormats.FileDrop), String())
Dim i As Integer
folderbrowserDialog1.ShowDialog()
For i = 0 To clipbrd.Length - 1
If System.IO.File.Exists(folderbrowserDialog1.Selecte dPath _
& System.IO.Path.GetFileName(clipbrd(i))) Then
System.IO.File.Move(folderbrowserDialog1.SelectedP ath & _
"\" & _
System.IO.Path.GetFileName(clipbrd(i)), _
folderbrowserDialog1.SelectedPath & "temptemptemp.temp")
End If
System.IO.File.Copy(clipbrd(i), folderbrowserDialog1.SelectedPath & _
"\" & _
System.IO.Path.GetFileName(clipbrd(i)))
If System.IO.File.Exists(folderbrowserDialog1.Selecte dPath _
& "temptemptemp.temp") Then
System.IO.File.Delete(folderbrowserDialog1.Selecte dPath & _
"temptemptemp.temp")
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,
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
>
>



Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: tabonni | last post by:
Hi all I want to create an ASP page, which can copy the real PDF files into the clipboard and then the user can paste it in Outlook message as...
5
by: tabonni | last post by:
Hello All I am creating an ASP page. There are a list of filename and checkbox next to it. When user checked all the documents they want and...
3
by: Tor Inge Rislaa | last post by:
Copy, Cut and Paste How to code the Copy, Cut and Paste functionality in VB.NET. In VB 6.0 I used the following code: 'For Copy ...
2
by: Keith | last post by:
I'm trying to come up with a way to create a contextmenu that will do all the "standard" functions (cut, copy, paste, undo, etc). There seems to...
7
by: lgbjr | last post by:
Hello All, Im using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard...
6
by: Ben R. | last post by:
Hi, I've got a vb.net winforms app. Out of the box, I can use Ctrl X, C and V as expected in controls like textboxes. I've got a menustrip, and...
8
by: serge calderara | last post by:
Dear all, I have an treeview control with different node object, I would like to implement the Copy/Paste function of an object . For that I am...
17
by: Steve | last post by:
I'm trying to code cut, copy, and paste in vb 2005 so that when the user clicks on a toolbar button, the cut/copy/paste will work with whatever...
8
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.