By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

Copy and Paste Files to and from the Clipboard

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.